Here's a demonstration of how it is failing in Neutron. It seems to be an issue with the relationship and it being referenced.
from sqlalchemy import * from sqlalchemy.orm import * from sqlalchemy.ext.declarative import declarative_base
Base = declarative_base()
class B(Base): __tablename__ = 'b' a_id = Column(Integer, ForeignKey('a.id', ondelete="CASCADE"), nullable=True) address = Column(String(36), nullable=False, primary_key=True)
class A(Base): __tablename__ = 'a' id = Column(Integer, primary_key=True) b_recs = relationship(B, backref='A', lazy='joined', passive_deletes='all')
e = create_engine("sqlite://", echo=True) Base.metadata.create_all(e)
s = Session(e, autocommit=True)
try: with s.begin(): a1 = A(id=1) s.add(a1)
s.flush() s.add(B(a_id=1, address='1234'))
# other code references relationship assert a1.b_recs
# a1 is now persistent assert inspect(a1).persistent
# exception is raised raise Exception("something broke") except Exception: # context manager has called rollback()
# a1 is no longer persistent, it's bumped out assert a1 not in s assert inspect(a1).transient
# retry - no problem with a2 with s.begin(): a2 = A(id=1) s.add(a2) s.add(B(a_id=1, address='1234'))
assert inspect(a1).transient assert inspect(a2).persistent
Here's a demonstration of how it is failing in Neutron. It seems to be an issue with the relationship and it being referenced.
from sqlalchemy import * ext.declarative import declarative_base
from sqlalchemy.orm import *
from sqlalchemy.
Base = declarative_base()
class B(Base): "CASCADE" ),
nullable= True)
__tablename__ = 'b'
a_id = Column(Integer, ForeignKey('a.id', ondelete=
address = Column(String(36), nullable=False, primary_key=True)
class A(Base):
passive_ deletes= 'all')
__tablename__ = 'a'
id = Column(Integer, primary_key=True)
b_recs = relationship(B, backref='A', lazy='joined',
e = create_ engine( "sqlite: //", echo=True) create_ all(e)
Base.metadata.
s = Session(e, autocommit=True)
try:
with s.begin():
a1 = A(id=1)
s.add(a1)
s.flush()
s.add( B(a_id= 1, address='1234'))
# other code references relationship
assert a1.b_recs
# a1 is now persistent a1).persistent
assert inspect(
# exception is raised "something broke")
raise Exception(
except Exception:
# context manager has called rollback()
# a1 is no longer persistent, it's bumped out a1).transient
assert a1 not in s
assert inspect(
# retry - no problem with a2
s.add( B(a_id= 1, address='1234'))
with s.begin():
a2 = A(id=1)
s.add(a2)
assert inspect( a1).transient a2).persistent
assert inspect(