I'm getting this error with the following code. Unfortunately none of the
code in the stacktrace is my code, it's all SQLAlchemy stuff, so I can't
tell where I'm causing the problem.
Traceback (most recent call last):
File
"/home/user/.virtualenvs/project/lib/python3.4/site-packages/pyramid_debugtoolbar-2.2.2-py3.4.egg/pyramid_debugtoolbar/panels/performance.py"
, line 57, in resource_timer_handler
result = handler(request)
File
"/home/user/.virtualenvs/project/lib/python3.4/site-packages/pyramid-1.5.1-py3.4.egg/pyramid/tweens.py"
, line 21, in excview_tween
response = handler(request)
File
"/home/user/.virtualenvs/project/lib/python3.4/site-packages/pyramid_tm-0.8-py3.4.egg/pyramid_tm/__init__.py"
, line 92, in tm_tween
reraise(*exc_info)
File
"/home/user/.virtualenvs/project/lib/python3.4/site-packages/pyramid_tm-0.8-py3.4.egg/pyramid_tm/compat.py"
, line 13, in reraise
raise value
File
"/home/user/.virtualenvs/project/lib/python3.4/site-packages/pyramid_tm-0.8-py3.4.egg/pyramid_tm/__init__.py"
, line 80, in tm_tween
manager.commit()
File
"/home/user/.virtualenvs/project/lib/python3.4/site-packages/transaction-1.4.3-py3.4.egg/transaction/_manager.py"
, line 111, in commit
return self.get().commit()
File
"/home/user/.virtualenvs/project/lib/python3.4/site-packages/transaction-1.4.3-py3.4.egg/transaction/_transaction.py"
, line 280, in commit
reraise(t, v, tb)
File
"/home/user/.virtualenvs/project/lib/python3.4/site-packages/transaction-1.4.3-py3.4.egg/transaction/_compat.py"
, line 55, in reraise
raise value
File
"/home/user/.virtualenvs/project/lib/python3.4/site-packages/transaction-1.4.3-py3.4.egg/transaction/_transaction.py"
, line 271, in commit
self._commitResources()
File
"/home/user/.virtualenvs/project/lib/python3.4/site-packages/transaction-1.4.3-py3.4.egg/transaction/_transaction.py"
, line 417, in _commitResources
reraise(t, v, tb)
File
"/home/user/.virtualenvs/project/lib/python3.4/site-packages/transaction-1.4.3-py3.4.egg/transaction/_compat.py"
, line 55, in reraise
raise value
File
"/home/user/.virtualenvs/project/lib/python3.4/site-packages/transaction-1.4.3-py3.4.egg/transaction/_transaction.py"
, line 394, in _commitResources
rm.tpc_vote(self)
File
"/home/user/.virtualenvs/project/lib/python3.4/site-packages/zope.sqlalchemy-0.7.5-py3.4.egg/zope/sqlalchemy/datamanager.py"
, line 103, in tpc_vote
self.tx.commit()
File
"/home/user/.virtualenvs/project/lib/python3.4/site-packages/SQLAlchemy-0.9.8-py3.4-linux-x86_64.egg/sqlalchemy/orm/session.py"
, line 375, in commit
self._assert_active(prepared_ok=True)
File
"/home/user/.virtualenvs/project/lib/python3.4/site-packages/SQLAlchemy-0.9.8-py3.4-linux-x86_64.egg/sqlalchemy/orm/session.py"
, line 223, in _assert_active
raise sa_exc.ResourceClosedError(closed_msg)
sqlalchemy.exc.ResourceClosedError: This transaction is closed
Here I try to add a user, and when I flush it if I get an IntegrityError it
means the user already exists.
In this case I search for another object Action. If I get NoResultFound I
create a new one and try to insert it.
And it's here that the exception happens. Any idea how I can fix this?
DBSession.add(user)
try:
DBSession.flush()
except sqlalchemy.exc.IntegrityError as e:
# User already exists
DBSession.rollback()
user = DBSession.query(User).filter(User.email == email).one()
try:
action = DBSession.query(Action).filter(Action.name == name,
Action.param == None).one()
except sqlalchemy.orm.exc.NoResultFound:
action = create_new_action()
DBSession.add(action)
return HTTPFound(location=request.route_url('page'))
--
You received this message because you are subscribed to the Google Groups
"sqlalchemy" group.
To unsubscribe from this group and stop receiving emails from it, send an email
to [email protected].
To post to this group, send email to [email protected].
Visit this group at http://groups.google.com/group/sqlalchemy.
For more options, visit https://groups.google.com/d/optout.