]> git.ipfire.org Git - thirdparty/sqlalchemy/sqlalchemy.git/commitdiff
- [bug] fixed inappropriate evaluation of user-mapped
authorMike Bayer <mike_mp@zzzcomputing.com>
Fri, 28 Oct 2011 15:53:32 +0000 (11:53 -0400)
committerMike Bayer <mike_mp@zzzcomputing.com>
Fri, 28 Oct 2011 15:53:32 +0000 (11:53 -0400)
object in a boolean context within query.get()
[ticket:2310].

CHANGES
lib/sqlalchemy/orm/query.py
test/orm/test_mapper.py

diff --git a/CHANGES b/CHANGES
index 74f1bdc024122fc43694919f3fd088e016330644..7a323fe2c90bfbab6af38edbadd04c54d30f4409 100644 (file)
--- 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]
 
index 88532d90961fd799b375ed0c46c6e5dd5a4c14de..a875ad46d06dc667860e32d5e30e9e09e99ba40d 100644 (file)
@@ -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)
 
index 78cc142fff8b86c79536f55b171ccfd81d21e1da..71bb10878e04fa538df3da065c9cbf770147f2f6 100644 (file)
@@ -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):