diff options
| author | Mike Bayer <mike_mp@zzzcomputing.com> | 2008-08-08 04:25:17 +0000 |
|---|---|---|
| committer | Mike Bayer <mike_mp@zzzcomputing.com> | 2008-08-08 04:25:17 +0000 |
| commit | 924ffe6dfa01e6fa5e264604a24119363cbc07b5 (patch) | |
| tree | b4d14ae71b4bf037975f73c1ae67cebb14a6248f | |
| parent | e93893af434eebf85a322e436d48ccd111f8f5d9 (diff) | |
| download | sqlalchemy-924ffe6dfa01e6fa5e264604a24119363cbc07b5.tar.gz | |
- Fixed bug regarding inherit_condition passed
with "A=B" versus "B=A" leading to errors
[ticket:1039]
| -rw-r--r-- | CHANGES | 7 | ||||
| -rw-r--r-- | lib/sqlalchemy/orm/mapper.py | 5 | ||||
| -rw-r--r-- | test/orm/inheritance/basic.py | 35 |
3 files changed, 45 insertions, 2 deletions
@@ -1,6 +1,13 @@ ======= CHANGES ======= +0.4.8 +===== +- orm + - Fixed bug regarding inherit_condition passed + with "A=B" versus "B=A" leading to errors + [ticket:1039] + 0.4.7p1 ===== - orm diff --git a/lib/sqlalchemy/orm/mapper.py b/lib/sqlalchemy/orm/mapper.py index d39e743e0..b86fdc07b 100644 --- a/lib/sqlalchemy/orm/mapper.py +++ b/lib/sqlalchemy/orm/mapper.py @@ -1578,12 +1578,13 @@ class Mapper(object): def visit_binary(binary): leftcol = binary.left rightcol = binary.right + if leftcol is None or rightcol is None: return if leftcol.table not in needs_tables: binary.left = sql.bindparam(None, None, type_=binary.right.type) param_names.append((leftcol, binary.left)) - elif rightcol not in needs_tables: + elif rightcol.table not in needs_tables: binary.right = sql.bindparam(None, None, type_=binary.right.type) param_names.append((rightcol, binary.right)) @@ -1595,7 +1596,7 @@ class Mapper(object): break if not mapper.single: allconds.append(visitors.traverse(mapper.inherit_condition, clone=True, visit_binary=visit_binary)) - + return sql.and_(*allconds), param_names Mapper.logger = logging.class_logger(Mapper) diff --git a/test/orm/inheritance/basic.py b/test/orm/inheritance/basic.py index cb754fed5..f59973d02 100644 --- a/test/orm/inheritance/basic.py +++ b/test/orm/inheritance/basic.py @@ -275,7 +275,42 @@ class GetTest(ORMTest): test_get_polymorphic = create_test(True, 'test_get_polymorphic') test_get_nonpolymorphic = create_test(False, 'test_get_nonpolymorphic') +class InheritConditionTest(ORMTest): + def define_tables(self, metadata): + global base, child + base = Table('base', metadata, + Column('id', Integer, primary_key = True), + Column('type', String(40))) + + child = Table('child', metadata, + Column('base_id', Integer, ForeignKey(base.c.id), primary_key = True), + Column('title', String(64)), + Column('parent_id', Integer, ForeignKey('child.base_id')) + ) + + def test_inherit_cond(self): + class Base(fixtures.Base): + pass + class Child(Base): + pass + + mapper(Base, base, polymorphic_on=base.c.type) + mapper(Child, child, inherits=Base, inherit_condition=child.c.base_id==base.c.id, polymorphic_identity='c') + + sess = create_session() + sess.save(Child(title='c1')) + sess.save(Child(title='c2')) + sess.flush() + sess.clear() + for inherit_cond in (child.c.base_id==base.c.id, base.c.id==child.c.base_id): + clear_mappers() + mapper(Base, base, polymorphic_on=base.c.type) + mapper(Child, child, inherits=Base, inherit_condition=inherit_cond, polymorphic_identity='c') + + assert sess.query(Base).order_by(Base.id).all() == [Child(title='c1'), Child(title='c2')] + + class ConstructionTest(ORMTest): def define_tables(self, metadata): global content_type, content, product |
