inheritance, lazy loading and m:n relation to an ancestor
Issue #123
resolved
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('foo.id'), primary_key=True))
bar_foo = Table('bar_foo', engine,
Column('bar_id', Integer, ForeignKey('bar.id')),
Column('foo_id', Integer, ForeignKey('foo.id'))
)
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()
bar.insert().execute(id=1)
foo.insert().execute()
bar.insert().execute(id=2)
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)
-
Account Deleted -
repo owner - changed status to resolved
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.
- Log in to comment
This test computes as of 2cc08018bdc985c3dc5557dd0773eda431253295, however there's a new issue quite related. demo for that coming later.