I'm currently suffering from a rare and hard to pin down bug that
seems to be living somewhere in contextual session code. As part of a
formencode schema, I'm checking to make sure that a submitted form
value matches a record in the database. From tracing through the
request lifecycle, it should be the first query in the thread and
therefore should have a totally fresh session. However, I've been
getting a rollback exception.
This is the stack trace:
====================
⇝ InvalidRequestError: The transaction is inactive due to a rollback
in a subtransaction. Issue rollback() to cancel the transaction.
clear this
Module ?:1 in <lambda> view
Module pylons.decorators:134 in wrapper view
<< log.debug("Validating against a schema")
try:
self.form_result = schema.to_python(decoded,
state)
except formencode.Invalid, e:
errors = e.unpack_errors(variable_decode,
dict_char, list_char)
>> self.form_result = schema.to_python(decoded, state)
Module formencode.api:413 in to_python view
<< tp = self._to_python
if tp:
value = tp(value, state)
vp = self.validate_python
if vp and vp is not self._validate_noop:
>> value = tp(value, state)
Module formencode.schema:153 in _to_python view
<< try:
new[name] = validator.to_python(value,
state)
except Invalid, e:
errors[name] = e
>> new[name] = validator.to_python(value, state)
Module formencode.api:416 in to_python view
<< vp = self.validate_python
if vp and vp is not self._validate_noop:
vp(value, state)
return value
except Invalid:
>> vp(value, state)
Module barcode.lib.helpers:50 in validate_python view
<< def validate_python(self, value, state):
#TODO: Determine if we want to check against the
standard
check = model.Check.getCheck(imb=value)
if check is not None:
raise Invalid(self.message('duplicate_imb', state),
value, state)
>> check = model.Check.getCheck(imb=value)
Module barcode.model:111 in getCheck view
<< args.append(Check.imb==kwargs['imb'])
try:
return meta.Session.query(Check).filter(and_
(*args)).one()
except NoResultFound:
return None
>> return meta.Session.query(Check).filter(and_(*args)).one()
Module sqlalchemy.orm.query:1019 in one view
<< "use `first()` instead.")
ret = list(self[0:2])
if len(ret) == 1:
>> ret = list(self[0:2])
Module sqlalchemy.orm.query:923 in __getitem__ view
<< return list(res)[None:None:item.step]
else:
return list(res)
else:
return list(self[item:item+1])[0]
>> return list(res)
Module sqlalchemy.orm.query:1034 in __iter__ view
<< if self._autoflush and not self._populate_existing:
self.session._autoflush()
return self._execute_and_instances(context)
def _execute_and_instances(self, querycontext):
>> return self._execute_and_instances(context)
Module sqlalchemy.orm.query:1037 in _execute_and_instances
view
<< def _execute_and_instances(self, querycontext):
result = self.session.execute(querycontext.statement,
params=self._params, mapper=self._mapper_zero_or_none(),
_state=self._refresh_state)
return self.instances(result, querycontext)
>> result = self.session.execute(querycontext.statement, params=self._params,
>> mapper=self._mapper_zero_or_none(), _state=self._refresh_state)
Module sqlalchemy.orm.session:744 in execute view
<< engine = self.get_bind(mapper, clause=clause,
_state=_state)
return self.__connection(engine,
close_with_result=True).execute(
clause, params or {})
>> return self.__connection(engine, close_with_result=True).execute(
Module sqlalchemy.orm.session:711 in __connection view
<< def __connection(self, engine, **kwargs):
if self.transaction is not None:
return self.transaction._connection_for_bind
(engine)
else:
return engine.contextual_connect(**kwargs)
>> return self.transaction._connection_for_bind(engine)
Module sqlalchemy.orm.session:310 in _connection_for_bind view
<< def _connection_for_bind(self, bind):
self._assert_is_active()
if bind in self._connections:
>> self._assert_is_active()
Module sqlalchemy.orm.session:245 in _assert_is_active view
<< if not self._active:
raise sa_exc.InvalidRequestError(
"The transaction is inactive due to a rollback
in a "
"subtransaction. Issue rollback() to cancel
the transaction.")
>> "The transaction is inactive due to a rollback in a "
InvalidRequestError: The transaction is inactive due to a rollback in
a subtransaction. Issue rollback() to cancel the transaction.
====================
If I enter the debugger at :
====================
Module barcode.model:111 in getCheck view
<< args.append(Check.imb==kwargs['imb'])
try:
return meta.Session.query(Check).filter(and_
(*args)).one()
except NoResultFound:
return None
>> return meta.Session.query(Check).filter(and_(*args)).one()
====================
and enter the query line, half of the time I get the rollback
exception, and half of the time I get the expected result. Similar
events occur if I move up the stack and execute other queries.
However, as soon as I enter the debugger at:
====================
Module sqlalchemy.orm.query:1019 in one view
<< "use `first()` instead.")
ret = list(self[0:2])
if len(ret) == 1:
>> ret = list(self[0:2])
====================
any attempts to manipulate self[foo] result in the rollback
exception. Any thoughts as to the cause?
--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the Google Groups
"sqlalchemy" group.
To post to this group, send email to [email protected]
To unsubscribe from this group, send email to
[email protected]
For more options, visit this group at
http://groups.google.com/group/sqlalchemy?hl=en
-~----------~----~----~----~------~----~------~--~---