stanfordnmbl / opencap-api

Apache License 2.0
5 stars 7 forks source link

Download session not working on dev server. #6

Closed antoinefalisse closed 1 year ago

antoinefalisse commented 1 year ago

See details here: https://github.com/stanfordnmbl/opencap-api-private/issues/89

antoinefalisse commented 1 year ago

Copying the older issue:

Downloading sessions is not working on the dev server.

Initially, I thought the problem is that the host is hardcoded as in this example:

https://github.com/stanfordnmbl/opencap-api/blob/22c3a2d23654596ab3e43f650c1588a703b1433b/mcserver/zipsession.py#L72

However, once this is solved, another error appeared. This is the new error message:

./mcserver/zipsession.py, line 188, in getSessionJson
        188. session['trials'].sort(key=getCreatedAt)

And these are the variable values at that point:

getCreatedAt | .getCreatedAt at 0x7fc72da5c680> -- | -- host | 'https://dev.opencap.ai' resp | session | {'detail': 'Invalid token.'} session_id | '90e869e9-34d8-4235-b989-aec3df23e764'

The session returns invalid token. The session value is assigned a few lines above.

182.     resp = requests.get(host + "/sessions/{}/".format(session_id),
                     headers = {"Authorization": "Token {}".format(API_TOKEN)})
         session = resp.json()

The API_TOKEN is retrieved from environment variables in the line 12 of the file:

https://github.com/stanfordnmbl/opencap-api/blob/22c3a2d23654596ab3e43f650c1588a703b1433b/mcserver/zipsession.py#L12

In the server, this is retrieved from secrets, and there is only one secret called API_KEY, shared between the main server and the dev server. My guess is that this API_TOKEN is not correct for the dev server, and it is causing this to fail.

This is not a critical problem, since it is working properly in the main server, but makes impossible to test the "Download" functionality in the dev branch before merging to the main branch. This could potentially cause bugs to be propagated to the main branch.

antoinefalisse commented 1 year ago

Solved now with celery workers as long as we have celery workers running for dev