summaryrefslogtreecommitdiff
path: root/test/perf
diff options
context:
space:
mode:
authorMike Bayer <mike_mp@zzzcomputing.com>2010-04-10 19:21:54 -0400
committerMike Bayer <mike_mp@zzzcomputing.com>2010-04-10 19:21:54 -0400
commit44c67fef8cc578ffbca409ad95e6471b4cb4d02a (patch)
tree564d8a340da815b5179ea06236be4b5981eea400 /test/perf
parenta6c0057b74604235e2c6066be7e9f28644c67fa8 (diff)
downloadsqlalchemy-44c67fef8cc578ffbca409ad95e6471b4cb4d02a.tar.gz
- starting to groom the branch for its inclusion
- one-to-many relationships now maintain a list of positive parent-child associations within the flush, preventing previous parents marked as deleted from cascading a delete or NULL foreign key set on those child objects, despite the end-user not removing the child from the old association. [ticket:1764] - re-established Preprocess as unique on their arguments, as they were definitely duped in inheritance scenarios - added a "memo" feature to UOWTransaction which represents the usual pattern of using the .attributes collection - added the test case from [ticket:1081] into perf/
Diffstat (limited to 'test/perf')
-rw-r--r--test/perf/large_flush.py84
1 files changed, 84 insertions, 0 deletions
diff --git a/test/perf/large_flush.py b/test/perf/large_flush.py
new file mode 100644
index 000000000..431a28944
--- /dev/null
+++ b/test/perf/large_flush.py
@@ -0,0 +1,84 @@
+import sqlalchemy as sa
+from sqlalchemy import create_engine, MetaData, orm
+from sqlalchemy import Column, ForeignKey
+from sqlalchemy import Integer, String
+from sqlalchemy.orm import mapper
+from sqlalchemy.test import profiling
+
+class Object(object):
+ pass
+
+class Q(Object):
+ pass
+
+class A(Object):
+ pass
+
+class C(Object):
+ pass
+
+class WC(C):
+ pass
+
+engine = create_engine('sqlite:///:memory:', echo=True)
+
+sm = orm.sessionmaker(bind=engine)
+
+SA_Session = orm.scoped_session(sm)
+
+SA_Metadata = MetaData()
+
+object_table = sa.Table('Object',
+ SA_Metadata,
+ Column('ObjectID', Integer,primary_key=True),
+ Column('Type', String(1), nullable=False))
+
+q_table = sa.Table('Q',
+ SA_Metadata,
+ Column('QID', Integer, ForeignKey('Object.ObjectID'),primary_key=True))
+
+c_table = sa.Table('C',
+ SA_Metadata,
+ Column('CID', Integer, ForeignKey('Object.ObjectID'),primary_key=True))
+
+wc_table = sa.Table('WC',
+ SA_Metadata,
+ Column('WCID', Integer, ForeignKey('C.CID'), primary_key=True))
+
+a_table = sa.Table('A',
+ SA_Metadata,
+ Column('AID', Integer, ForeignKey('Object.ObjectID'),primary_key=True),
+ Column('QID', Integer, ForeignKey('Q.QID')),
+ Column('CID', Integer, ForeignKey('C.CID')))
+
+mapper(Object, object_table, polymorphic_on=object_table.c.Type, polymorphic_identity='O')
+
+mapper(Q, q_table, inherits=Object, polymorphic_identity='Q')
+mapper(C, c_table, inherits=Object, polymorphic_identity='C')
+mapper(WC, wc_table, inherits=C, polymorphic_identity='W')
+
+mapper(A, a_table, inherits=Object, polymorphic_identity='A',
+ properties = {
+ 'Q' : orm.relation(Q,primaryjoin=a_table.c.QID==q_table.c.QID,
+ backref='As'
+ ),
+ 'C' : orm.relation(C,primaryjoin=a_table.c.CID==c_table.c.CID,
+ backref='A',
+ uselist=False)
+ }
+ )
+
+SA_Metadata.create_all(engine)
+
+@profiling.profiled('large_flush', always=True, sort=['file'])
+def generate_error():
+ q = Q()
+ for j in range(100): #at 306 the error does not pop out (depending on recursion depth)
+ a = A()
+ a.Q = q
+ a.C = WC()
+
+ SA_Session.add(q)
+ SA_Session.commit() #here the error pops out
+
+generate_error() \ No newline at end of file