]> 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:17 +0000 (11:53 -0400)
committerMike Bayer <mike_mp@zzzcomputing.com>
Fri, 28 Oct 2011 15:53:17 +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 742a32eae7325b5d3b0f398262586faf9cacefea..5f4f9cf59e777e81d960e50ddf5f940473a4a420 100644 (file)
--- 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,
index 5dc216670a563d98d7bde7d73ccb05345020b976..6065c7a1cc2cdedbcc769b77fd7ae1e44d135d23 100644 (file)
@@ -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
index 005f3eb8a9ac93608aaff4a5179189ae27a5f713..abbbf03869a2db67bed207cd64dd29337e92c5a2 100644 (file)
@@ -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):