From: Mike Bayer Date: Fri, 28 Oct 2011 15:53:32 +0000 (-0400) Subject: - [bug] fixed inappropriate evaluation of user-mapped X-Git-Tag: rel_0_7_4~69 X-Git-Url: http://git.ipfire.org/?a=commitdiff_plain;h=a870d1c401fb4da3139743cafc6c5e29d988faee;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 74f1bdc024..7a323fe2c9 100644 --- a/CHANGES +++ b/CHANGES @@ -12,6 +12,10 @@ CHANGES generates columns to put up onto the base. - orm + - [bug] fixed inappropriate evaluation of user-mapped + object in a boolean context within query.get() + [ticket:2310]. Also in 0.6.9. + - [bug] Added missing comma to PASSIVE_RETURN_NEVER_SET symbol [ticket:2304] diff --git a/lib/sqlalchemy/orm/query.py b/lib/sqlalchemy/orm/query.py index 88532d9096..a875ad46d0 100644 --- a/lib/sqlalchemy/orm/query.py +++ b/lib/sqlalchemy/orm/query.py @@ -2240,7 +2240,7 @@ class Query(object): """ instance = session.identity_map.get(key) - if instance: + if instance is not None: state = attributes.instance_state(instance) diff --git a/test/orm/test_mapper.py b/test/orm/test_mapper.py index 78cc142fff..71bb10878e 100644 --- a/test/orm/test_mapper.py +++ b/test/orm/test_mapper.py @@ -690,6 +690,18 @@ class MapperTest(_fixtures.FixtureTest): s.add(A()) s.commit() + def test_we_dont_call_bool(self): + class NoBoolAllowed(object): + def __nonzero__(self): + raise Exception("nope") + mapper(NoBoolAllowed, self.tables.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 + def test_we_dont_call_eq(self): class NoEqAllowed(object): def __eq__(self, other):