Getting the user executing the script in Dataiku notebook

Presenna
Presenna Registered Posts: 2 ✭✭
edited May 15 in Using Dataiku

Hi, we are running a python "notebook" in dataiku and in the code, we would want the id of the user who is running the notebook (as opposed to who created the notebook session). Sometimes multiple users open it in parallel and run in which case we have a need to see which user is actually running the notebook. At the moment all the options we tried, gives us only the session creator. Below are the options we tried.

Option 1:

client.get_own_user().get_settings().get_raw()['login']

Option 2:

client.get_auth_info()['authIdentifier']

Option 3:

getpass.getuser() → This gives us the dsx user id and not any actual user.

Looking for help in this regard. Thanks!

Answers

  • Yasmine_T
    Yasmine_T Registered Posts: 39 ✭✭✭

    Hi,

    I hope that you are doing well.

    I would need a bit of clarification regarding your use case.

    Is the goal here to prevent multiple user from making notebook changes/run in parallel through checking if another user is currently running or making updates to this specific notebook?

    Could you provide some more context regarding this?

    Best,

    Yasmine

  • Presenna
    Presenna Registered Posts: 2 ✭✭

    Thanks for the response. To answer your question, the intention is to send the id of the user (who is running the notebook) in a header while making an external API call. We don't want to add any restrictions to multiple users editing or running notebooks inparallel.

  • Turribeach
    Turribeach Dataiku DSS Core Designer, Neuron, Dataiku DSS Adv Designer, Registered, Neuron 2023 Posts: 2,501 Neuron

    What you want to do probably can't be done and it's probably the wrong thing to ask for. All those statements you posted will give you the correct User ID if you use a recipe instead of a Jupyter Notebook. Jupyter Notebooks are a different beast as they don't take the identity of the user ID that's running them but the one that started the Python kernel, which is why you see the other user ID.

    Jupyter Notebook are meant to be used to explore datasets and develop models, there are not really meant as operational process. At the very least you should move your code to a Python recipe which will identify the user ID running it properly. In fact if this is going to be something a lot of users run you could develop a Dataiku webapp which will easily be able to run Python code and identify who the user is.

Setup Info
    Tags
      Help me…