oTree Forum >

random.choices() returning error while creating session

#1 by AndreL (edited )

I have the following in one of my apps

class C(BaseConstants):
    STATES = ['down', 'up']
class Player(BasePlayer):
    state = models.StringField()    

def creating_session(subsession: Subsession):
    import random
    for plr in subsession.get_players():

If I use within that loop
... I get a roughly even split between 'down' and 'up'

However, I want a weighted random choice, thus I try the choices method instead
    plr.state=random.choices(C.STATES, weights=(10, 90), k=1)
... and then I get a failure to create the session as below. Any help or suggestions on what could be happening?

Failed to create session: (raised as a result of Query-invoked autoflush; consider using a session.no_autoflush block if this flush is occurring prematurely) (sqlite3.InterfaceError) Error binding parameter 8 - probably unsupported type.

#2 by AndreL (edited )


#3 by Chris_oTree

Try using a print statement to see what random.choices is returning.

Write a reply

Set forum username