The Pyramid framework uses the Zope transaction manager to supply a
unit-of-work. From its PKG-INFO:
Name: transaction
Summary: Transaction management for Python
Home-page: http://www.zope.org/Products/ZODB
Author: Zope Corporation
This package contains a generic transaction implementation for
Python. It is
mainly used by the ZODB, though.
It is injected in SA's session like this:
DbSession =
scoped_session(sessionmaker(extension=ZopeTransactionExtension()))
If we call session.commit(), the program will bail with an assertion error,
telling we have to use the transaction manager's commit(). This is the way
to go
import transaction
transaction.commit()
-----------------------
I have updated my code to use
sess.query(_Entity).filter(_Entity.id==id).delete(synchronize_session=False)
In some cases it works, in one case it does not, but instead behaves like
the code in post 1. The statement is issued (at least, the SA logger prints
it, but I assume it never reaches the database), no errors, no rollbacks,
but the record stays in the database.
Because the code sometimes is successful, I assume the problem to be in the
model, rather than in the session/transaction management. I use declarative
model classes like this:
Principal ----- 1:n-------+
RoleMember
Role ------------ 1:n------+
The deletes are successful on Principal and Role, the problem occurs on
RoleMember which is declared like this:
class RoleMember(DbBase, PymMixin):
__tablename__ = "rolemember"
__table_args__ = (
UniqueConstraint('role_id', 'principal_id'),
{'schema': 'pym'}
)
principal_id = Column(BigInteger,
ForeignKey("pym.principal.id", onupdate="CASCADE",
ondelete="CASCADE"),
nullable=False)
role_id = Column(BigInteger,
ForeignKey("pym.role.id", onupdate="CASCADE",
ondelete="CASCADE"),
nullable=False)
role = relationship('Role', backref='principal_assocs')
principal = relationship('Principal',
primaryjoin='Principal.id==RoleMember.principal_id',
backref='role_assocs' )
def __str__(self):
return "<RoleMember(id={0}, role_id='{1}',
principal_id='{2}'>".format(
self.id, self.role_id, self.principal_id)
I'm now studying the docs if there's an argument for relationship() that
prevents the delete. Or sth. similar...
Any illumination on this is welcome ;)
Dirk
--
You received this message because you are subscribed to the Google Groups
"sqlalchemy" group.
To view this discussion on the web visit
https://groups.google.com/d/msg/sqlalchemy/-/r92Fs2pQs3AJ.
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.