Issue #123 resolved

inheritance, lazy loading and m:n relation to an ancestor

Anonymous created an issue

When inheriting from an ancestor, defining an m:n relation to this ancestor and then using a relation in a property with lazy=True the wrong amount of rows is returned.

Below a test programm for that.

from sqlalchemy import *

engine = create_engine('oracle://dsn=orcl&user=test&password=test')

foo = Table('foo', engine, Column('id', Integer, Sequence('foo_seq'), primary_key=True))
bar = Table('bar', engine, Column('id', Integer, ForeignKey(''), primary_key=True))

bar_foo = Table('bar_foo', engine,
    Column('bar_id', Integer, ForeignKey('')),
    Column('foo_id', Integer, ForeignKey(''))

class Foo(object): pass
class Bar(object): pass

foos = mapper(Foo, foo)
bars = mapper(Bar, bar, inherits=foos)
bars.add_property('bad', relation(foos, bar_foo, lazy=True))
bars.add_property('good', relation(foos, bar_foo, lazy=False))

tables = foo, bar, bar_foo

for table in reversed(tables):
    try: table.drop()
    except Exception, e: print e

for table in tables:
    try: table.create()
    except Exception, e: print e



foo.insert().execute() #3
foo.insert().execute() #4

bar_foo.insert().execute(bar_id=1, foo_id=3)
bar_foo.insert().execute(bar_id=2, foo_id=4)

print len(bars.selectone().bad) #this is lazy=True and it should not print 2 but 1
print len(bars.selectone().good)

Comments (2)

  1. Mike Bayer repo owner

    this has been fixed in changeset:1179 this script added to unittests in changeset:1180....lazy whereclause construction was going off the parent Mappers "table", which represented the inheritance join, instead of the newer "noninherited_table" member, which represents the table local to the mapper.

    open a new ticket for your new bug.

  2. Log in to comment