Unable to locate interview session. Starting a new session instead.
Hi,
When I click "Save and run" from the playgound I end up on the first page of my interview. After completing the fields and pressing the "Continue" button I sometimes end up with the following message:

The fields are blanked and I have to start filling the fields all over again.
In the logs there is only one line:
docassemble: ip=XXX i=na uid=na user=XXX 2021-12-06 09:25:31 index: dictionary fetch returned no results
I haven't find a way to reproduce this every time but it appears within 5 attempts on some projects. ~~It seems to not appear when I use "Save" then "Run".~~
I run docassemble behind a company proxy for SSO authentication (not sure it helps but I dit not reproduce it yet with a more classic install).
Do you have any clue on how to try to solve this? I'm trying to see in the "Save and run" code if something could go wrong there.
Ok I reproduced it with "Save" then "Run". Could there be a race condition between the "Save" and the launch of the interview in the other tab? I noticed that most of the times when the error happens is when the post request (save) is taking several seconds.
The "Save and Run" button in the Playground sends an Ajax request to the browser to save the new YAML, but also opens a new tab in /playground_redirect, which polls Redis waiting for a URL (it waits for up to 15 seconds), and when it gets the URL it will redirect to that URL. The Redis key it uses is unique to the user. The Ajax request that saves the YAML writes a URL to Redis when it is done saving the new YAML. That URL is a /interview URL with &reset=1. The &reset=1 means "delete any interview sessions I had previously started in this web browser session, then start a new session in this interview." (See https://docassemble.org/docs/interviews.html#reset)
The way that interview sessions work with browser cookies, you can only have one session in a given interview running in a web browser session at one time. If you try to have multiple sessions in the same interview going on at the same time in the same web browser (without using an incognito tab) you'll run into troubles.
Other ways that sessions can get deleted are:
- The user clicking an "exit" button.
- The user navigating to
/exit. - Running
command('exit')in Python code in the interview session. - The server deleting stale sessions according to the
interview delete daysConfiguration directive. - The user deleting their interview sessions on the "My Interviews" page.
- The user deleting their user data from the profile page.
I don't really know what is going on with your server/interview. The server might be really slow, which causes problems with the dual Ajax/new tab redirect thing?
Note that the system is not compatible with multiple browser sessions using the Playground at the same time.
Thank you for that,
Yes the server is slow but the response definitely arrives before 15 seconds. I manage to reproduce the error on a fresh serrver without all the proxy stuff. It happens way less often, if you don't try a lot of times, you may even never notice that.
Interview was:
---
objects:
fruit: DAList.using(object_type=DAObject, there_are_any=True)
---
question: |
Welcome to the interview ${interview_url()}
continue button field: intro_question
---
question: What is your favorite vgetable?
fields:
- Vegetable: favorite_vegetable
---
question: |
Tell me about the fruit
fields:
- Fruit name: fruit[i].name
required: False
- Number of seeds: fruit[i].seeds
required: False
list collect: True
---
table: fruit.table
rows: fruit
columns:
- Fruit Name: row_item.name
- Seeds: row_item.seeds
edit:
- name.text
---
event: final_screen
question: |
Summary of fruit
subquestion: |
${ len(fruit)}
---
mandatory: True
code: |
intro_question
fruit[0].name
favorite_vegetable
final_screen
If the error does not happen when clicking on continue, I close the tab and retry "Save and Run" from the playground.
Can take a while but it happens. So yeah maybe race conditions between the two requests or something like that and it aggravated with a slow server.
What's weird is that it does not appear at the same frequency depending on the project.
Does the save request to /playground change something in the user dict?
I noticed the variable json is {success:"false"} in the source tab so I'm wondering if this could happen:
- save request is sent
- playground_redirect is polling
- the url is pushed into Redis
- the new tab is redirected to the interview and the user_dict is reset
- in the still running save request, something prevents the user_dict to be filled with the new data (lock or something)
What I don't understand is that the session should be resetting so how could the user_dict be None (server.py line 6294) whereas we are resetting it just above. The fact that the error does not happen when just 'Run' but 'Save and Run' makes me think that the slow save request may be impacting one way or another.
user_dict is None because Python had a session ID and it tried to query the SQL database for the interview answers associated with that session ID, and the SQL server returned zero results. So it concludes that the session ID is no longer good, and it starts a new interview.
I have changed the code so that if you press "Save," you can't press any other buttons until the save process has completed. Likewise if you press "Save and Run," you can't press any other buttons until the Ajax call returns. Hopefully this will prevent the problem from happening.
I am closing this issue because it is inactive but it can be reopened if there are further issues.