Failed to create session: Textual column expression 'id' should be explicitly declared

393 views
Skip to first unread message

Valery Pavlov

unread,
May 15, 2021, 5:05:33 AM5/15/21
to oTree help & discussion
Hello,

I had used oTree earlier, v.3. Now I installed v.5.1.10 but it does not see to work. As always, I use "oTree devserver" in the PyCharm terminal window, the admin interface seem functioning but when I try to create a session I am getting an error: 

Failed to create session: Textual column expression 'id' should be explicitly declared with text('id'), or use column('id') for more specificity

Traceback (most recent call last): File "D:\...\oTree_code\venv\lib\site-packages\otree\session.py", line 442, in create_session_traceback_wrapper return create_session(**kwargs)

If you know how to fix this, could you please help?

Regards
Valery

Valery Pavlov

unread,
May 15, 2021, 5:17:59 AM5/15/21
to oTree help & discussion
The complete traceback is the following:

  File "D:\...\oTree_code\venv\lib\site-packages\otree\session.py", line 442, in create_session_traceback_wrapper return create_session(**kwargs)
  File "D:\...\oTree_code\venv\lib\site-packages\otree\session.py", line 348, in create_session     dbq(Subsession)
  File "", line 2, in with_entities 
  File "D:\...\oTree_code\venv\lib\site-packages\sqlalchemy\sql\base.py", line 106, in _generative     x = fn(self, *args, **kw)
  File "D:\...\oTree_code\venv\lib\site-packages\sqlalchemy\orm\query.py", line 1436, in with_entities     self._set_entities(entities)
  File "D:\...\oTree_code\venv\lib\site-packages\sqlalchemy\orm\query.py", line 182, in _set_entities     self._raw_columns = [
  File "D:\...\oTree_code\venv\lib\site-packages\sqlalchemy\orm\query.py", line 183, in     coercions.expect(
  File "D:\...\oTree_code\venv\lib\site-packages\sqlalchemy\sql\coercions.py", line 175, in expect     resolved = impl._literal_coercion(
  File "D:\...\oTree_code\venv\lib\site-packages\sqlalchemy\sql\coercions.py", line 375, in _literal_coercion     return self._text_coercion(element, argname, **kw)
  File "D:\...\oTree_code\venv\lib\site-packages\sqlalchemy\sql\coercions.py", line 804, in _text_coercion     raise exc.ArgumentError(
sqlalchemy.exc.ArgumentError: Textual column expression 'id' should be explicitly declared with text('id'), or use column('id') for more specificity

Chris @ oTree

unread,
May 15, 2021, 5:45:20 AM5/15/21
to oTree help & discussion
Can you show the full output of "pip freeze"?

Chris @ oTree

unread,
May 15, 2021, 5:48:19 AM5/15/21
to oTree help & discussion
Also, can you narrow down which app is causing this error? Try removing all apps except one from the app_sequence, and see if the error still happens.
When you have found a single app that causes this error, please send me the code of the Subsession class for that app.

Valery Pavlov

unread,
May 15, 2021, 6:09:10 AM5/15/21
to oTree help & discussion
Thanks, Chris. Sure:

>pip freeze
WARNING: Ignoring invalid distribution -etuptools (d:\...\otree_code\venv\lib\site-packages)
aiofiles==0.6.0
boto3==1.17.73
botocore==1.20.73
click==8.0.0
colorama==0.4.4
docutils==0.17.1
greenlet==1.1.0
h11==0.12.0
itsdangerous==2.0.0
jmespath==0.10.0
MarkupSafe==2.0.0
otree==5.1.10
python-dateutil==2.8.1
python-multipart==0.0.5
s3transfer==0.4.2
six==1.16.0
SQLAlchemy==1.4.15
starlette==0.14.2
urllib3==1.26.4
uvicorn==0.13.4
websockets==9.0.1
WTForms==2.3.3
WTForms-SQLAlchemy==0.2

Chris @ oTree

unread,
May 15, 2021, 6:18:47 AM5/15/21
to oTree help & discussion
For some reason you ended up with a different version of SQLAlchemy. Try this again: "pip3 install -U otree". it should install sqlalchemy 1.3.22.

Valery Pavlov

unread,
May 15, 2021, 6:21:02 AM5/15/21
to oTree help & discussion
I have used the demo apps in oTree Studio. Downloaded and unpackked .otreezip. Please see below the content of settings.py,  models.py and pages.py. The  init.py is empty.

***
settings.py:
from os import environ

SESSION_CONFIG_DEFAULTS = dict(real_world_currency_per_point=1,
participation_fee=0)
SESSION_CONFIGS = [dict(name='my_session',
num_demo_participants=3,
app_sequence=['public_goods'])]
LANGUAGE_CODE = 'en'
REAL_WORLD_CURRENCY_CODE = 'USD'
USE_POINTS = True
PARTICIPANT_FIELDS = []
SESSION_FIELDS = []
ROOMS = []

ADMIN_USERNAME = 'admin'
# for security, best to set admin password in an environment variable
ADMIN_PASSWORD = environ.get('OTREE_ADMIN_PASSWORD')

SECRET_KEY = 'blahblah'

# if an app is included in SESSION_CONFIGS, you don't need to list it here
INSTALLED_APPS = ['otree']

DEMO_PAGE_INTRO_HTML = """
Here are some oTree games.
"""

***

from otree.api import (
models, widgets, BaseConstants, BaseSubsession, BaseGroup, BasePlayer,
Currency as c, currency_range, Page, WaitPage
)
cu = c

doc = '\nThis is a one-period public goods game with 3 players.\n'
class Constants(BaseConstants):
name_in_url = 'public_goods'
players_per_group = 3
num_rounds = 1
endowment = c(100)
multiplier = 2
admin_report_template = 'public_goods/admin_report.html'
instructions_template = 'public_goods/instructions.html'
def vars_for_admin_report(subsession):
session = subsession.session
contributions = [p.contribution for p in subsession.get_players() if p.contribution != None]
if contributions:
return dict(
avg_contribution=sum(contributions) / len(contributions),
min_contribution=min(contributions),
max_contribution=max(contributions),
)
else:
return dict(
avg_contribution='(no data)',
min_contribution='(no data)',
max_contribution='(no data)',
)
class Subsession(BaseSubsession):
vars_for_admin_report = vars_for_admin_report
def set_payoffs(group):
group.total_contribution = sum([p.contribution for p in group.get_players()])
group.individual_share = (
group.total_contribution * Constants.multiplier / Constants.players_per_group
)
for p in group.get_players():
p.payoff = (Constants.endowment - p.contribution) + group.individual_share
class Group(BaseGroup):
total_contribution = models.CurrencyField()
individual_share = models.CurrencyField()
set_payoffs = set_payoffs
class Player(BasePlayer):
contribution = models.CurrencyField(doc='The amount contributed by the player', label='How much will you contribute to the project from 0 to 100', max=Constants.endowment, min=0)

***
pages.py:

from .models import *

class Introduction(Page):
form_model = 'player'
class Contribute(Page):
form_model = 'player'
form_fields = ['contribution']
class ResultsWaitPage(WaitPage):
after_all_players_arrive = 'set_payoffs'
body_text = 'Waiting for other participants to contribute.'
class Results(Page):
form_model = 'player'
def vars_for_template(self):
group = self.group
return dict(total_earnings=group.total_contribution * Constants.multiplier)
page_sequence = [Introduction, Contribute, ResultsWaitPage, Results]

Valery Pavlov

unread,
May 15, 2021, 6:26:28 AM5/15/21
to oTree help & discussion
This fixed the issue, seem to be working now. I think I ended up with a more recent version because PyCharm showed there is a newer one and I clicked "update" :)

Thanks a lot! 
I *very* much appreciate your prompt help!

Regards
Valery

Chris @ oTree

unread,
May 15, 2021, 6:33:02 AM5/15/21
to oTree help & discussion
Ok good. In the past I recall there would be an error if any wrong versions were installed. I might investigate this...could be due to a change in pip/setuptools.
Reply all
Reply to author
Forward
0 new messages