From: Mike Bayer Date: Fri, 9 Sep 2011 19:51:40 +0000 (-0400) Subject: - Fixed bug whereby if __eq__() was X-Git-Tag: rel_0_7_3~59 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=1492cc634ee67afb5ad03f0d56caca9fc3bbcc0e;p=thirdparty%2Fsqlalchemy%2Fsqlalchemy.git - Fixed bug whereby if __eq__() was redefined, a relationship many-to-one lazyload would hit the __eq__() and fail. [ticket:2260] Does not apply to 0.6.9. --- diff --git a/CHANGES b/CHANGES index 62267025d9..644c152c4e 100644 --- a/CHANGES +++ b/CHANGES @@ -34,6 +34,11 @@ CHANGES on a new mapper would establish a backref on the first mapper. + - Fixed bug whereby if __eq__() was + redefined, a relationship many-to-one lazyload + would hit the __eq__() and fail. [ticket:2260] + Does not apply to 0.6.9. + -sql - Fixed bug regarding calculation of "from" list for a select() element. The "from" calc is now diff --git a/lib/sqlalchemy/orm/attributes.py b/lib/sqlalchemy/orm/attributes.py index a24348c860..42fdf7e7f8 100644 --- a/lib/sqlalchemy/orm/attributes.py +++ b/lib/sqlalchemy/orm/attributes.py @@ -421,7 +421,7 @@ class AttributeImpl(object): else: value = ATTR_EMPTY - if value in (PASSIVE_NO_RESULT, NEVER_SET): + if value is PASSIVE_NO_RESULT or value is NEVER_SET: return value elif value is ATTR_WAS_SET: try: diff --git a/test/ext/test_sqlsoup.py b/test/ext/test_sqlsoup.py index 88601b5cfb..09e7535b2c 100644 --- a/test/ext/test_sqlsoup.py +++ b/test/ext/test_sqlsoup.py @@ -279,6 +279,12 @@ class SQLSoupTest(fixtures.TestBase): db.users.relate('loans', db.loans, order_by=db.loans.loan_date, cascade='all, delete-orphan') + def test_relate_m2o(self): + db = sqlsoup.SqlSoup(engine) + db.loans.relate('user', db.users) + u1 = db.users.filter(db.users.c.name=='Joe Student').one() + eq_(db.loans.first().user, u1) + def test_explicit_session(self): Session = scoped_session(sessionmaker()) db = sqlsoup.SqlSoup(engine, session=Session) diff --git a/test/orm/test_mapper.py b/test/orm/test_mapper.py index ba477e8e6d..ce729ed6bf 100644 --- a/test/orm/test_mapper.py +++ b/test/orm/test_mapper.py @@ -690,6 +690,28 @@ class MapperTest(_fixtures.FixtureTest): s.add(A()) s.commit() + def test_we_dont_call_eq(self): + class NoEqAllowed(object): + def __eq__(self, other): + raise Exception("nope") + + addresses, users = self.tables.addresses, self.tables.users + Address = self.classes.Address + + mapper(NoEqAllowed, users, properties={ + 'addresses':relationship(Address, backref='user') + }) + mapper(Address, addresses) + + u1 = NoEqAllowed() + u1.name = "some name" + u1.addresses = [Address(id=12, email_address='a1')] + s = Session(testing.db) + s.add(u1) + s.commit() + + a1 = s.query(Address).filter_by(id=12).one() + assert a1.user is u1 def test_mapping_to_join_raises(self): """Test implicit merging of two cols raises."""