Error when advancing page (disable autoflush ?)

332 views
Skip to first unread message

Vitor Freire

unread,
Jul 23, 2021, 4:17:23 PM7/23/21
to oTree help & discussion
Hi Chris,

I was running a pre-test of the experiment and participants found an error when proceeding from one page to another (an specific page). Looking at the Redis app I got the following error description:

"(raised as a result of Query-invoked autoflush; consider using a session.no_autoflush block if this flush is occurring prematurely) (psycopg2.errors.NumericValueOutOfRange) integer out of range"

I googled it but I've found only some technical discussion (e.g., they comment on disabling the autoflush). But, the reality is that I have no idea of what is the "autoflush"and what might have gone wrong with my code that produced this error.

Can you help me shed some light on this?


Thanks

Chris @ oTree

unread,
Jul 23, 2021, 4:26:05 PM7/23/21
to Vitor Freire, oTree help & discussion
Seems like you have a numeric value out of range. Basically you are storing a too large number an IntegerField/FloatField. I have seen this happen with JavaScript timestamps, which are such big numbers that they exceed postgres's range for numeric fields. Better to store it in a StringField or somehow round/truncate it before storing into an IntegerField.

Sent from my phone

On Jul 23, 2021, at 2:17 PM, Vitor Freire <vit...@gmail.com> wrote:

Hi Chris,
--
You received this message because you are subscribed to the Google Groups "oTree help & discussion" group.
To unsubscribe from this group and stop receiving emails from it, send an email to otree+un...@googlegroups.com.
To view this discussion on the web, visit https://groups.google.com/d/msgid/otree/bdef133f-2586-4a80-8bd5-5bdaf4c037c5n%40googlegroups.com.

Chris @ oTree

unread,
Jul 23, 2021, 4:26:31 PM7/23/21
to Vitor Freire, oTree help & discussion
Also can you show the full trace back?

Sent from my phone

On Jul 23, 2021, at 2:26 PM, ch...@otree.org wrote:

Seems like you have a numeric value out of range. Basically you are storing a too large number an IntegerField/FloatField. I have seen this happen with JavaScript timestamps, which are such big numbers that they exceed postgres's range for numeric fields. Better to store it in a StringField or somehow round/truncate it before storing into an IntegerField.

Vitor Freire

unread,
Jul 23, 2021, 7:22:30 PM7/23/21
to oTree help & discussion
Ah ok, it makes sense, I really have an Integer field in the page A. I'll implement the solutions you outlined.
Thanks, Chris.

Here is what I think is the full track that you mean:

NumericValueOutOfRange: integer out of range

 

  File "sqlalchemy/engine/base.py", line 1276, in _execute_context

    self.dialect.do_execute(

  File "sqlalchemy/engine/default.py", line 609, in do_execute

    cursor.execute(statement, parameters)

DataError: (raised as a result of Query-invoked autoflush; consider using a session.no_autoflush block if this flush is occurring prematurely)

(psycopg2.errors.NumericValueOutOfRange) integer out of range

 

[SQL: UPDATE risk_ambiguity_other_player SET chave_pix=%(chave_pix)s, banco=%(banco)s, agencia=%(agencia)s, conta=%(conta)s, tipo_de_conta=%(tipo_de_conta)s, email_recibo=%(email_recibo)s, telefone=%(telefone)s WHERE risk_ambiguity_other_player.id = %(risk_ambiguity_other_player_id)s]

[parameters: {'chave_pix': '...

  File "uvicorn/protocols/http/h11_impl.py", line 396, in run_asgi

    result = await app(self.scope, self.receive, self.send)

  File "uvicorn/middleware/proxy_headers.py", line 45, in __call__

    return await self.app(scope, receive, send)

  File "starlette/applications.py", line 112, in __call__

    await self.middleware_stack(scope, receive, send)

  File "starlette/middleware/base.py", line 26, in __call__

    await response(scope, receive, send)

  File "starlette/responses.py", line 224, in __call__

    await run_until_first_complete(

  File "starlette/concurrency.py", line 24, in run_until_first_complete

    [task.result() for task in done]

  File "starlette/concurrency.py", line 24, in <listcomp>

    [task.result() for task in done]

  File "starlette/responses.py", line 216, in stream_response

    async for chunk in self.body_iterator:

  File "starlette/middleware/base.py", line 56, in body_stream

    task.result()

  File "starlette/middleware/base.py", line 38, in coro

    await self.app(scope, receive, send)

  File "otree/errorpage.py", line 247, in __call__

    raise exc  # from None

  File "otree/errorpage.py", line 227, in __call__

    await self.app(scope, receive, _send)

  File "starlette/middleware/base.py", line 25, in __call__

    response = await self.dispatch_func(request, self.call_next)

  File "otree/middleware.py", line 42, in dispatch

    response = await call_next(request)

  File "starlette/middleware/base.py", line 45, in call_next

    task.result()

  File "starlette/middleware/base.py", line 38, in coro

    await self.app(scope, receive, send)

  File "starlette/middleware/sessions.py", line 75, in __call__

    await self.app(scope, receive, send_wrapper)

  File "otree/patch.py", line 41, in __call__

    raise exc  # from None

  File "otree/patch.py", line 29, in __call__

    await self.app(scope, receive, sender)

  File "starlette/routing.py", line 582, in __call__

    await route.handle(scope, receive, send)

  File "starlette/routing.py", line 243, in handle

    await self.app(scope, receive, send)

  File "otree/views/abstract.py", line 109, in dispatch

    response = await run_in_threadpool(self.inner_dispatch, request)

  File "starlette/concurrency.py", line 40, in run_in_threadpool

    return await loop.run_in_executor(None, func, *args)

  File "concurrent/futures/thread.py", line 52, in run

    result = self.fn(*self.args, **self.kwargs)

  File "otree/views/abstract.py", line 400, in inner_dispatch

    return self.post()

  File "otree/views/abstract.py", line 611, in post

    self._increment_index_in_pages()

  File "otree/views/abstract.py", line 309, in _increment_index_in_pages

    page.set_attributes(self.participant)

  File "otree/views/abstract.py", line 242, in set_attributes

    self.player = self.PlayerClass.objects_get(

  File "otree/database.py", line 359, in objects_get

    return cls.objects_filter(*args, **kwargs).one()

  File "sqlalchemy/orm/query.py", line 3490, in one

    ret = self.one_or_none()

  File "sqlalchemy/orm/query.py", line 3459, in one_or_none

    ret = list(self)

  File "sqlalchemy/orm/query.py", line 3534, in __iter__

    self.session._autoflush()

  File "sqlalchemy/orm/session.py", line 1633, in _autoflush

    util.raise_(e, with_traceback=sys.exc_info()[2])

  File "sqlalchemy/util/compat.py", line 182, in raise_

    raise exception

  File "sqlalchemy/orm/session.py", line 1622, in _autoflush

    self.flush()

  File "sqlalchemy/orm/session.py", line 2540, in flush

    self._flush(objects)

  File "sqlalchemy/orm/session.py", line 2682, in _flush

    transaction.rollback(_capture_exception=True)

  File "sqlalchemy/util/langhelpers.py", line 68, in __exit__

    compat.raise_(

  File "sqlalchemy/util/compat.py", line 182, in raise_

    raise exception

  File "sqlalchemy/orm/session.py", line 2642, in _flush

    flush_context.execute()

  File "sqlalchemy/orm/unitofwork.py", line 422, in execute

    rec.execute(self)

  File "sqlalchemy/orm/unitofwork.py", line 586, in execute

    persistence.save_obj(

  File "sqlalchemy/orm/persistence.py", line 230, in save_obj

    _emit_update_statements(

  File "sqlalchemy/orm/persistence.py", line 994, in _emit_update_statements

    c = cached_connections[connection].execute(

  File "sqlalchemy/engine/base.py", line 1011, in execute

    return meth(self, multiparams, params)

  File "sqlalchemy/sql/elements.py", line 298, in _execute_on_connection

    return connection._execute_clauseelement(self, multiparams, params)

  File "sqlalchemy/engine/base.py", line 1124, in _execute_clauseelement

    ret = self._execute_context(

  File "sqlalchemy/engine/base.py", line 1316, in _execute_context

    self._handle_dbapi_exception(

  File "sqlalchemy/engine/base.py", line 1510, in _handle_dbapi_exception

    util.raise_(

  File "sqlalchemy/util/compat.py", line 182, in raise_

    raise exception

  File "sqlalchemy/engine/base.py", line 1276, in _execute_context

    self.dialect.do_execute(

  File "sqlalchemy/engine/default.py", line 609, in do_execute

    cursor.execute(statement, parameters)

Reply all
Reply to author
Forward
0 new messages