oTree Forum >

Application error (500) in created session while playing the app in Demo works fine

#1 by Aysegul_Engin ,

Hello, 

I encountered a curious issue and cannot manage to solve it on my own. Any help is greatly appreciated. 

I have an app that consists of 2 pages and multiple rounds. On the first page, 2 decisions require user input (FloatFields) and on the second page consequences of these decisions are shown. To calculate the consequences there is a couple of function calls before_next_page.

My issue is the following: While the app works fine using the oTree Demo mode it throws a TypeError if I try to play the same game after I create a session under Create Session tab. (TypeError: player.investment_num_scooter_translated is None. Accessing a null field is generally considered an error. Or, if this is intentional, use field_maybe_none()) 

Now I am definitely running the same code on both Demo and Create Session cases. If I monitor the data while I enter numbers in the input fields, oTree registers these and shows me user-inputted data in the Demo version in the database. However, it fails to do it in the created session. 

Function calls before_next_page need the user input for the calculations. So if the user input is not on the database it fails to calculate. This results in the TypeError. Until here I understand. 

But can anyone please help me out why the same code saves the input to the database and does the subsequent calculations without a problem in the demo mode and fails to do so in the created session? 

I have to conduct the experiment in the next days. So any help is greatly appreciated. 

System Info: 
MacOS Ventura 13.1
Python Version 3.11.1
oTree Version 5.10.2

kind regards, 
Aysegul

#2 by Scott

You should do your calculations in a wait page after BOTH players have submitted their values. Looking at the screenshot player 1 submits their value and then in your ..normalise_translate.. method, you loop through all the players and extract that value - but player 2 has not submitted it yet.

Use a wait page with a group level method, it save multiple gets anyway: https://otree.readthedocs.io/en/latest/multiplayer/waitpages.html#after-all-players-arrive

#3 by Aysegul_Engin ,

Hi Scott, 

I understand the idea and I would have done as you suggested if I had multiple players in a group. 

But in my case, all players are playing individually. So there are no groups essentially. 

Therefore I was packing all method calls under before_next_page(player) in a similar manner to calculating the scores of a questionnaire. 

E.g.

@staticmethod
    def before_next_page(player: Player, timeout_happened):
        set_method_1(player)
        set_method_2(player)

Write a reply

Set forum username