]> git.ipfire.org Git - thirdparty/sqlalchemy/sqlalchemy.git/commitdiff
- added "lockmode" kw argument to Session.refresh(), will
authorMike Bayer <mike_mp@zzzcomputing.com>
Fri, 19 Mar 2010 17:10:13 +0000 (13:10 -0400)
committerMike Bayer <mike_mp@zzzcomputing.com>
Fri, 19 Mar 2010 17:10:13 +0000 (13:10 -0400)
pass through the string value to Query the same as
in with_lockmode(), will also do version check for a
version_id_col-enabled mapping.

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

diff --git a/CHANGES b/CHANGES
index d7103893ffd2dfc8fb5e192ace5240b0017b17d4..2e11bd38a1d156d02d2d863e220b7ca264793125 100644 (file)
--- a/CHANGES
+++ b/CHANGES
@@ -20,6 +20,11 @@ CHANGES
     callable that, given the current value of the "version_id_col",
     returns the next version number.  Can be used for alternate
     versioning schemes such as uuid, timestamps.  [ticket:1692]
+  
+  - added "lockmode" kw argument to Session.refresh(), will
+    pass through the string value to Query the same as  
+    in with_lockmode(), will also do version check for a 
+    version_id_col-enabled mapping.
     
   - Fixed bug in session.rollback() which involved not removing
     formerly "pending" objects from the session before
index 0543cd38dd5b459ed2375c55fe382ba78a74b46e..0a3fbe79e26175dc81481ed978cbbd30494db017 100644 (file)
@@ -882,7 +882,7 @@ class Session(object):
         for state, dict_ in states.items():
             state.commit_all(dict_, self.identity_map)
 
-    def refresh(self, instance, attribute_names=None):
+    def refresh(self, instance, attribute_names=None, lockmode=None):
         """Refresh the attributes on the given instance.
 
         A query will be issued to the database and all attributes will be
@@ -895,9 +895,13 @@ class Session(object):
         Eagerly-loaded relational attributes will eagerly load within the
         single refresh operation.
 
-        The ``attribute_names`` argument is an iterable collection of
-        attribute names indicating a subset of attributes to be refreshed.
-
+        :param attribute_names: optional.  An iterable collection of
+          string attribute names indicating a subset of attributes to 
+          be refreshed.
+        
+        :param lockmode: Passed to the :class:`~sqlalchemy.orm.query.Query` 
+          as used by :meth:`~sqlalchemy.orm.query.Query.with_lockmode`.
+        
         """
         try:
             state = attributes.instance_state(instance)
@@ -906,6 +910,7 @@ class Session(object):
         self._validate_persistent(state)
         if self.query(_object_mapper(instance))._get(
                 state.key, refresh_state=state,
+                lockmode=lockmode,
                 only_load_props=attribute_names) is None:
             raise sa_exc.InvalidRequestError(
                 "Could not refresh instance '%s'" %
index d10a4c2bbb30fd001dff94baa6775cf3d2844621..f146e57b8a36bb840be95fceb76f943983d27215 100644 (file)
@@ -125,16 +125,29 @@ class VersioningTest(_base.MappedTest):
         s2.commit()
 
         # load, version is wrong
-        assert_raises(sa.orm.exc.ConcurrentModificationError, s1.query(Foo).with_lockmode('read').get, f1s1.id)
+        assert_raises(
+                sa.orm.exc.ConcurrentModificationError, 
+                s1.query(Foo).with_lockmode('read').get, f1s1.id
+            )
+
+        # load, version is wrong
+        assert_raises(
+                sa.orm.exc.ConcurrentModificationError, 
+                s1.refresh, f1s1, lockmode='read'
+            )
 
         # reload it
         s1.query(Foo).populate_existing().get(f1s1.id)
+        
         # now assert version OK
         s1.query(Foo).with_lockmode('read').get(f1s1.id)
 
         # assert brand new load is OK too
         s1.close()
         s1.query(Foo).with_lockmode('read').get(f1s1.id)
+        
+        
+        
 
     @testing.emits_warning(r'.*does not support updated rowcount')
     @engines.close_open_connections