summaryrefslogtreecommitdiff
path: root/lib/sqlalchemy/orm/session.py
diff options
context:
space:
mode:
authorMike Bayer <mike_mp@zzzcomputing.com>2010-03-19 13:10:13 -0400
committerMike Bayer <mike_mp@zzzcomputing.com>2010-03-19 13:10:13 -0400
commitb2741d8b77e630552c6d5749f5f427860976bb8d (patch)
tree5a87db20282e917c2f1c44cf1dd4195eaf2aedca /lib/sqlalchemy/orm/session.py
parent7de2b6923f214674cf139b21125f41c2752094eb (diff)
downloadsqlalchemy-b2741d8b77e630552c6d5749f5f427860976bb8d.tar.gz
- 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.
Diffstat (limited to 'lib/sqlalchemy/orm/session.py')
-rw-r--r--lib/sqlalchemy/orm/session.py13
1 files changed, 9 insertions, 4 deletions
diff --git a/lib/sqlalchemy/orm/session.py b/lib/sqlalchemy/orm/session.py
index 0543cd38d..0a3fbe79e 100644
--- a/lib/sqlalchemy/orm/session.py
+++ b/lib/sqlalchemy/orm/session.py
@@ -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'" %