Hello! I’m hoping to get some help with a problem that I can’t seem to solve using Python functions.
Context
I’m building a page in Workshop to manage user permissions, which are stored in a Ontology object. One of the requirements for the “create permission” form is to have a dropdown to select a user. This is easily solved with the standard User Selector Widget.
The Problem
The User Selector widget outputs the selected user’s User ID (e.g., 123e4567-e89b-12d3-a456-426614174000). However, for a better user experience, I need the user’s Username.
What I’ve Tried
My first thought was to create a simple Python function that takes the User ID and returns the username using the FoundryClient:
from ontology_sdk import FoundryClient
from functions.api import function
@function()
def get_username(user_id: str) -> str:
client = FoundryClient()
# Attempt to get the user object by their ID
user = client.users.get_user(user_id)
return user.username
However, when I run this, I get the following error, which suggests that the users attribute is not part of the FoundryClient available in this context.
AttributeError: ‘FoundryClient’ object has no attribute ‘users’
The Question
I’ve seen multiple topics on the forums that solve this using Typescript functions, but I am required to use a Python Functions Repository for this project.
Is there a standard or simple way to get a user’s details (like their username) from a given User ID inside a Python function?
You can try the foundry-platform-sdk.
There the admin module has a function to get the user. I am not sure how it works though considering that this function does not work in the Ontology but in the code repository that I am working in…
If I try this, the error message is: raise ConnectionError(str(e)) from e foundry_sdk._errors.connection_error.ConnectionError: [Errno -2] Name or service not known
Any idea regarding this? I was already quite happy that I could get the user without putting it in as an argument of the function.