]> git.ipfire.org Git - thirdparty/sqlalchemy/sqlalchemy.git/commitdiff
- Fixed bug whereby session.is_modified() would raise an exception
authorMike Bayer <mike_mp@zzzcomputing.com>
Thu, 9 Jul 2009 01:45:44 +0000 (01:45 +0000)
committerMike Bayer <mike_mp@zzzcomputing.com>
Thu, 9 Jul 2009 01:45:44 +0000 (01:45 +0000)
if any synonyms were in use.

CHANGES
lib/sqlalchemy/orm/session.py
test/orm/test_session.py

diff --git a/CHANGES b/CHANGES
index cf2f8150d162e57403749d8f1dbdae0a9f2753b6..16b21f634ad2b77204fefe781e9ae26ce6f0332b 100644 (file)
--- a/CHANGES
+++ b/CHANGES
@@ -31,6 +31,9 @@ CHANGES
       wouldn't be deserialized correctly when the whole object
       was serialized.  [ticket:1426]
 
+    - Fixed bug whereby session.is_modified() would raise an exception
+      if any synonyms were in use.
+      
     - Fixed Query being able to join() from individual columns of
       a joined-table subclass entity, i.e.
       query(SubClass.foo, SubcClass.bar).join(<anything>).
index cbfb0c1d643a3a2d670b3a29b4968a7dbc38c7c8..a658783c2cbf7a3e33c31c11337d60e17c071cf8 100644 (file)
@@ -1473,10 +1473,18 @@ class Session(object):
             state = attributes.instance_state(instance)
         except exc.NO_STATE:
             raise exc.UnmappedInstanceError(instance)
+        dict_ = state.dict
         for attr in state.manager.attributes:
-            if not include_collections and hasattr(attr.impl, 'get_collection'):
+            if \
+                (
+                    not include_collections and 
+                    hasattr(attr.impl, 'get_collection')
+                ) or not hasattr(attr.impl, 'get_history'):
                 continue
-            (added, unchanged, deleted) = attr.get_history(instance, passive=passive)
+                
+            (added, unchanged, deleted) = \
+                    attr.impl.get_history(state, dict_, passive=passive)
+                                            
             if added or deleted:
                 return True
         return False
index 3020d66e9dcfc45caed78d60a6247c1e703c0b87..a94b4e7df727ab99d4c339583a83e6649877beea 100644 (file)
@@ -747,6 +747,16 @@ class SessionTest(_fixtures.FixtureTest):
         assert s.is_modified(user)
         assert not s.is_modified(user, include_collections=False)
 
+    @testing.resolve_artifact_names
+    def test_is_modified_syn(self):
+        s = sessionmaker()()
+
+        mapper(User, users, properties={'uname':sa.orm.synonym('name')})
+        u = User(uname='fred')
+        assert s.is_modified(u)
+        s.add(u)
+        s.commit()
+        assert not s.is_modified(u)
 
     @testing.resolve_artifact_names
     def test_weak_ref(self):