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?