summaryrefslogtreecommitdiff
path: root/test/orm/inheritance/test_basic.py
diff options
context:
space:
mode:
authorMike Bayer <mike_mp@zzzcomputing.com>2009-07-25 21:26:28 +0000
committerMike Bayer <mike_mp@zzzcomputing.com>2009-07-25 21:26:28 +0000
commitc1a36dfe4142cf630d0d3f4056fae43902cbcf6b (patch)
tree5e1964deb84837167a90be50d816d6d82563397f /test/orm/inheritance/test_basic.py
parenta510e9f23abe0df6eaa781094b191eb3178b2c7d (diff)
downloadsqlalchemy-c1a36dfe4142cf630d0d3f4056fae43902cbcf6b.tar.gz
- Fixed bug whereby a load/refresh of joined table
inheritance attributes which were based on column_property() or similar would fail to evaluate. [ticket:1480]
Diffstat (limited to 'test/orm/inheritance/test_basic.py')
-rw-r--r--test/orm/inheritance/test_basic.py66
1 files changed, 56 insertions, 10 deletions
diff --git a/test/orm/inheritance/test_basic.py b/test/orm/inheritance/test_basic.py
index 6aa77868e..bad6920de 100644
--- a/test/orm/inheritance/test_basic.py
+++ b/test/orm/inheritance/test_basic.py
@@ -915,10 +915,8 @@ class OverrideColKeyTest(_base.MappedTest):
assert sess.query(Sub).get(s1.base_id).data == "this is base"
class OptimizedLoadTest(_base.MappedTest):
- """test that the 'optimized load' routine doesn't crash when
- a column in the join condition is not available.
+ """tests for the "optimized load" routine."""
- """
@classmethod
def define_tables(cls, metadata):
global base, sub
@@ -933,7 +931,10 @@ class OptimizedLoadTest(_base.MappedTest):
)
def test_optimized_passes(self):
- class Base(object):
+ """"test that the 'optimized load' routine doesn't crash when
+ a column in the join condition is not available."""
+
+ class Base(_base.BasicEntity):
pass
class Sub(Base):
pass
@@ -943,21 +944,66 @@ class OptimizedLoadTest(_base.MappedTest):
# redefine Sub's "id" to favor the "id" col in the subtable.
# "id" is also part of the primary join condition
mapper(Sub, sub, inherits=Base, polymorphic_identity='sub', properties={'id':sub.c.id})
- sess = create_session()
- s1 = Sub()
- s1.data = 's1data'
- s1.sub = 's1sub'
+ sess = sessionmaker()()
+ s1 = Sub(data='s1data', sub='s1sub')
sess.add(s1)
- sess.flush()
+ sess.commit()
sess.expunge_all()
# load s1 via Base. s1.id won't populate since it's relative to
# the "sub" table. The optimized load kicks in and tries to
# generate on the primary join, but cannot since "id" is itself unloaded.
# the optimized load needs to return "None" so regular full-row loading proceeds
- s1 = sess.query(Base).get(s1.id)
+ s1 = sess.query(Base).first()
assert s1.sub == 's1sub'
+ def test_column_expression(self):
+ class Base(_base.BasicEntity):
+ pass
+ class Sub(Base):
+ pass
+ mapper(Base, base, polymorphic_on=base.c.type, polymorphic_identity='base')
+ mapper(Sub, sub, inherits=Base, polymorphic_identity='sub', properties={
+ 'concat':column_property(sub.c.sub + "|" + sub.c.sub)
+ })
+ sess = sessionmaker()()
+ s1 = Sub(data='s1data', sub='s1sub')
+ sess.add(s1)
+ sess.commit()
+ sess.expunge_all()
+ s1 = sess.query(Base).first()
+ assert s1.concat == 's1sub|s1sub'
+
+ def test_column_expression_joined(self):
+ class Base(_base.ComparableEntity):
+ pass
+ class Sub(Base):
+ pass
+ mapper(Base, base, polymorphic_on=base.c.type, polymorphic_identity='base')
+ mapper(Sub, sub, inherits=Base, polymorphic_identity='sub', properties={
+ 'concat':column_property(base.c.data + "|" + sub.c.sub)
+ })
+ sess = sessionmaker()()
+ s1 = Sub(data='s1data', sub='s1sub')
+ s2 = Sub(data='s2data', sub='s2sub')
+ s3 = Sub(data='s3data', sub='s3sub')
+ sess.add_all([s1, s2, s3])
+ sess.commit()
+ sess.expunge_all()
+ # query a bunch of rows to ensure there's no cartesian
+ # product against "base" occurring, it is in fact
+ # detecting that "base" needs to be in the join
+ # criterion
+ eq_(
+ sess.query(Base).order_by(Base.id).all(),
+ [
+ Sub(data='s1data', sub='s1sub', concat='s1data|s1sub'),
+ Sub(data='s2data', sub='s2sub', concat='s2data|s2sub'),
+ Sub(data='s3data', sub='s3sub', concat='s3data|s3sub')
+ ]
+ )
+
+
class PKDiscriminatorTest(_base.MappedTest):
@classmethod
def define_tables(cls, metadata):