From: Mike Bayer Date: Sun, 15 Nov 2009 20:39:39 +0000 (+0000) Subject: - Fixed bug whereby composite columns wouldn't load properly X-Git-Tag: rel_0_6beta1~164 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=734dce8b60320791efc85005f6a9dde116ff8898;p=thirdparty%2Fsqlalchemy%2Fsqlalchemy.git - Fixed bug whereby composite columns wouldn't load properly when configured on a joined-table subclass, introduced in version 0.5.6 as a result of the fix for [ticket:1480]. [ticket:1616] thx to Scott Torborg. --- diff --git a/CHANGES b/CHANGES index 917ea9b56f..0e45bf8526 100644 --- a/CHANGES +++ b/CHANGES @@ -719,6 +719,11 @@ CHANGES - Fixed bug where Query would crash if a join() with no clear "left" side were called when a non-mapped column entity appeared in the columns list. [ticket:1602] + + - Fixed bug whereby composite columns wouldn't load properly + when configured on a joined-table subclass, introduced in + version 0.5.6 as a result of the fix for [ticket:1480]. + [ticket:1616] thx to Scott Torborg. - sql - Fixed bug in two-phase transaction whereby commit() method diff --git a/lib/sqlalchemy/orm/mapper.py b/lib/sqlalchemy/orm/mapper.py index 146c4d6737..1c7c37ead7 100644 --- a/lib/sqlalchemy/orm/mapper.py +++ b/lib/sqlalchemy/orm/mapper.py @@ -1165,7 +1165,10 @@ class Mapper(object): cond = sql.and_(*allconds) - return sql.select([props[key].columns[0] for key in attribute_names], cond, use_labels=True) + cols = [] + for key in attribute_names: + cols.extend(props[key].columns) + return sql.select(cols, cond, use_labels=True) def cascade_iterator(self, type_, state, halt_on=None): """Iterate each element and its mapper in an object graph, diff --git a/test/orm/inheritance/test_basic.py b/test/orm/inheritance/test_basic.py index a682d38cb1..b02db4e1b3 100644 --- a/test/orm/inheritance/test_basic.py +++ b/test/orm/inheritance/test_basic.py @@ -1021,7 +1021,7 @@ class OptimizedLoadTest(_base.MappedTest): @classmethod def define_tables(cls, metadata): - global base, sub + global base, sub, with_comp base = Table('base', metadata, Column('id', Integer, primary_key=True, test_needs_autoincrement=True), Column('data', String(50)), @@ -1031,6 +1031,11 @@ class OptimizedLoadTest(_base.MappedTest): Column('id', Integer, ForeignKey('base.id'), primary_key=True), Column('sub', String(50)) ) + with_comp = Table('with_comp', metadata, + Column('id', Integer, ForeignKey('base.id'), primary_key=True), + Column('a', String(10)), + Column('b', String(10)) + ) def test_optimized_passes(self): """"test that the 'optimized load' routine doesn't crash when @@ -1104,6 +1109,35 @@ class OptimizedLoadTest(_base.MappedTest): Sub(data='s3data', sub='s3sub', concat='s3data|s3sub') ] ) + + def test_composite_column_joined(self): + class Base(_base.ComparableEntity): + pass + class WithComp(Base): + pass + class Comp(object): + def __init__(self, a, b): + self.a = a + self.b = b + def __composite_values__(self): + return self.a, self.b + def __eq__(self, other): + return (self.a == other.a) and (self.b == other.b) + mapper(Base, base, polymorphic_on=base.c.type, polymorphic_identity='base') + mapper(WithComp, with_comp, inherits=Base, polymorphic_identity='wc', properties={ + 'comp': composite(Comp, with_comp.c.a, with_comp.c.b) + }) + sess = sessionmaker()() + s1 = WithComp(data='s1data', comp=Comp('ham', 'cheese')) + s2 = WithComp(data='s2data', comp=Comp('bacon', 'eggs')) + sess.add_all([s1, s2]) + sess.commit() + sess.expunge_all() + s1test, s2test = sess.query(Base).order_by(Base.id).all() + assert s1test.comp + assert s2test.comp + eq_(s1test.comp, Comp('ham', 'cheese')) + eq_(s2test.comp, Comp('bacon', 'eggs')) class PKDiscriminatorTest(_base.MappedTest):