multi user session 1.7,0 accessing session inside update function

I’m loading and writing data to a custom database and inside the update function I want to access the current user session

e.g.
For http://localhost:8080?session=kabir
I want to add

{
   "annotator": "kabir"
}

to each example passed to the update callback.

Is there a way to do this easily?
Using get_db().sessions only returns the default date session (2019-02-21_04-30-03)

I need to think about this some more, but I don’t think there is at the moment, no. I definitely understand what you’re trying to do here, though. Maybe it’d make sense to have a feature like this built-in. If not by default, there could be a setting like "add_session_id_to_task" (or something like that).

One quick note about the update callback btw: The update callback only receives a copy of the example, so you can’t modify examples and have the changes reflected in the database. The reason for that is to ensure that what ends up in the database is exactly what the annotator saw and worked on. Otherwise, you only need one tiny bug in your code to potentially destroy all your data – and you might not even find out until much later.

If you want to play around with this in the meantime, you could have a look at the give_answers endpoint in prodigy/app.py. To find the location of your Prodigy installation, you can run the following:

python -c "import prodigy; print(prodigy.__file__)"

If a custom named session ID is set, give_answers will receive it as the session_id argument. So you could do the following:

for answer in answers:
    answer["session_id"] = session_id

Note that this will add the full session ID, like your_dataset-kabir, so you’d have to split the string if you only want the session identifier.

Yeah that’s what I meant in my post. Totally makes sense and it’s exactly the behavior I want.

I’ll take a look at the give_answers endpoint. I’m not sure this really warrants its own feature since it seems like a real edge case but would be a nice-to-have.

1 Like