How to change user context

Question about user context with the toolkit.
Let’s say I’m trying to grab the context like
ctx = tk.context_from_entity('Project', project['id'])
I come up as the user in this context. Where is shotgun getting this user info from? I’m not passing it as far as I know.
Does it come from the toolkit instance? If so, is there a way I can change who the context user is?

Thanks!

3 Likes

Just so I know that I’m not breaking anything by doing this but…
if I re-assign _Context__user to a different user, it appears to change it for the context instance overall. Is this correct?

1 Like

Quoting the docs for context.user, “The user property is special - either it represents a user value that was baked into a template path upon folder creation, or it represents the current user.”

Since with context_from_entity(), there’s no template path at play, the user in the context is coming from the current logged in user.

I’m not sure about _Context__user – let me see if I can get more info about it for you.

1 Like

Also the context is supposed to be immutable, and not changed on the fly.
Can I ask how you’re hoping to be able to use it? Maybe we can suggest something.

Hi Philip,

Actually I found the (I assume preferred) way of approaching my problem.
I wanted to change the publishing user. Then I found out that I can pass a publishing user to the publishing item’s properties and the publish script handles the rest of it.

Thanks!

2 Likes