From: Mike Bayer Date: Fri, 28 Oct 2011 15:53:17 +0000 (-0400) Subject: - [bug] fixed inappropriate evaluation of user-mapped X-Git-Tag: rel_0_6_9~20 X-Git-Url: http://git.ipfire.org/gitweb.cgi?a=commitdiff_plain;h=55a8c45b57fe7860f3743a6a269463ff327817ae;p=thirdparty%2Fsqlalchemy%2Fsqlalchemy.git - [bug] fixed inappropriate evaluation of user-mapped object in a boolean context within query.get() [ticket:2310]. --- diff --git a/CHANGES b/CHANGES index 742a32eae7..5f4f9cf59e 100644 --- a/CHANGES +++ b/CHANGES @@ -20,6 +20,10 @@ CHANGES if against a column expression that combined multiple entities together. [ticket:2197] + - [bug] fixed inappropriate evaluation of user-mapped + object in a boolean context within query.get() + [ticket:2310]. + - Fixed bug apparent only in Python 3 whereby sorting of persistent + pending objects during flush would produce an illegal comparison, diff --git a/lib/sqlalchemy/orm/query.py b/lib/sqlalchemy/orm/query.py index 5dc216670a..6065c7a1cc 100644 --- a/lib/sqlalchemy/orm/query.py +++ b/lib/sqlalchemy/orm/query.py @@ -1957,7 +1957,7 @@ class Query(object): not mapper.always_refresh and \ lockmode is None: instance = self.session.identity_map.get(key) - if instance: + if instance is not None: # item present in identity map with a different class if not issubclass(instance.__class__, mapper.class_): return None diff --git a/test/orm/test_mapper.py b/test/orm/test_mapper.py index 005f3eb8a9..abbbf03869 100644 --- a/test/orm/test_mapper.py +++ b/test/orm/test_mapper.py @@ -660,6 +660,18 @@ class MapperTest(_fixtures.FixtureTest): a1 = s.query(Address).filter_by(id=12).one() assert a1.user is u1 + @testing.resolve_artifact_names + def test_we_dont_call_bool(self): + class NoBoolAllowed(object): + def __nonzero__(self): + raise Exception("nope") + mapper(NoBoolAllowed, users) + u1 = NoBoolAllowed() + u1.name = "some name" + s = Session(testing.db) + s.add(u1) + s.commit() + assert s.query(NoBoolAllowed).get(u1.id) is u1 @testing.resolve_artifact_names def test_mapping_to_join_raises(self):