From 1a88a982b43f2f3a0735890b00a45e178727812f Mon Sep 17 00:00:00 2001 From: Mike Bayer Date: Sun, 4 Aug 2013 15:28:40 -0400 Subject: find some more inline imports and move them out --- lib/sqlalchemy/orm/loading.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) (limited to 'lib/sqlalchemy/orm/loading.py') diff --git a/lib/sqlalchemy/orm/loading.py b/lib/sqlalchemy/orm/loading.py index 1641f509e..c219ea096 100644 --- a/lib/sqlalchemy/orm/loading.py +++ b/lib/sqlalchemy/orm/loading.py @@ -19,6 +19,8 @@ from .interfaces import EXT_CONTINUE from ..sql import util as sql_util from .util import _none_set, state_str from .. import exc as sa_exc + +querylib = util.importlater("sqlalchemy.orm", "query") sessionlib = util.importlater("sqlalchemy.orm", "session") _new_runid = util.counter() @@ -101,8 +103,6 @@ def instances(query, cursor, context): def merge_result(query, iterator, load=True): """Merge a result into this :class:`.Query` object's Session.""" - from . import query as querylib - session = query.session if load: # flush current contents if we expect to load data -- cgit v1.2.1 From 59141d360e70d1a762719206e3cb0220b4c53fef Mon Sep 17 00:00:00 2001 From: Mike Bayer Date: Wed, 14 Aug 2013 19:58:34 -0400 Subject: - apply an import refactoring to the ORM as well - rework the event system so that event modules load after their targets, dependencies are reversed - create an improved strategy lookup system for the ORM - rework the ORM to have very few import cycles - move out "importlater" to just util.dependency - other tricks to cross-populate modules in as clear a way as possible --- lib/sqlalchemy/orm/loading.py | 8 +++----- 1 file changed, 3 insertions(+), 5 deletions(-) (limited to 'lib/sqlalchemy/orm/loading.py') diff --git a/lib/sqlalchemy/orm/loading.py b/lib/sqlalchemy/orm/loading.py index c219ea096..512a07d66 100644 --- a/lib/sqlalchemy/orm/loading.py +++ b/lib/sqlalchemy/orm/loading.py @@ -20,9 +20,6 @@ from ..sql import util as sql_util from .util import _none_set, state_str from .. import exc as sa_exc -querylib = util.importlater("sqlalchemy.orm", "query") -sessionlib = util.importlater("sqlalchemy.orm", "session") - _new_runid = util.counter() @@ -100,7 +97,8 @@ def instances(query, cursor, context): break -def merge_result(query, iterator, load=True): +@util.dependencies("sqlalchemy.orm.query") +def merge_result(querylib, query, iterator, load=True): """Merge a result into this :class:`.Query` object's Session.""" session = query.session @@ -547,7 +545,7 @@ def load_scalar_attributes(mapper, state, attribute_names): """initiate a column-based attribute refresh operation.""" #assert mapper is _state_mapper(state) - session = sessionlib._state_session(state) + session = state.session if not session: raise orm_exc.DetachedInstanceError( "Instance %s is not bound to a Session; " -- cgit v1.2.1 From d47a376863bd7c804e4396808841d06b78c0e13a Mon Sep 17 00:00:00 2001 From: Mike Bayer Date: Mon, 7 Oct 2013 12:53:04 -0400 Subject: - add an option to Bundle single_entity=True to allow for single entity returns without otherwise changing much [ticket:2824] --- lib/sqlalchemy/orm/loading.py | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) (limited to 'lib/sqlalchemy/orm/loading.py') diff --git a/lib/sqlalchemy/orm/loading.py b/lib/sqlalchemy/orm/loading.py index 512a07d66..93c94c9f4 100644 --- a/lib/sqlalchemy/orm/loading.py +++ b/lib/sqlalchemy/orm/loading.py @@ -33,7 +33,8 @@ def instances(query, cursor, context): for ent in query._entities] filtered = id in filter_fns - single_entity = filtered and len(query._entities) == 1 + single_entity = len(query._entities) == 1 and \ + query._entities[0].supports_single_entity if filtered: if single_entity: @@ -43,7 +44,7 @@ def instances(query, cursor, context): return tuple(fn(x) for x, fn in zip(row, filter_fns)) custom_rows = single_entity and \ - query._entities[0].mapper.dispatch.append_result + query._entities[0].custom_rows (process, labels) = \ list(zip(*[ -- cgit v1.2.1 From 248c4ef797421dec5dc7ec65bd805d5509a7abe4 Mon Sep 17 00:00:00 2001 From: Mike Bayer Date: Thu, 28 Nov 2013 23:31:17 -0500 Subject: - repair the "lockmode" functionality of load_on_ident(). slightly problematic here is that "lockmode" is also public in Session.refresh(). --- lib/sqlalchemy/orm/loading.py | 13 +++++++++---- 1 file changed, 9 insertions(+), 4 deletions(-) (limited to 'lib/sqlalchemy/orm/loading.py') diff --git a/lib/sqlalchemy/orm/loading.py b/lib/sqlalchemy/orm/loading.py index 93c94c9f4..dfb8f11a8 100644 --- a/lib/sqlalchemy/orm/loading.py +++ b/lib/sqlalchemy/orm/loading.py @@ -174,8 +174,6 @@ def load_on_ident(query, key, only_load_props=None): """Load the given identity key from the database.""" - lockmode = lockmode or query._lockmode - if key is not None: ident = key[1] else: @@ -213,10 +211,17 @@ def load_on_ident(query, key, q._params = params if lockmode is not None: - q._lockmode = lockmode + version_check = True + q = q.with_lockmode(lockmode) + elif query._for_update_arg is not None: + version_check = True + q._for_update_arg = query._for_update_arg + else: + version_check = False + q._get_options( populate_existing=bool(refresh_state), - version_check=(lockmode is not None), + version_check=version_check, only_load_props=only_load_props, refresh_state=refresh_state) q._order_by = None -- cgit v1.2.1 From f89d4d216bd7605c920b7b8a10ecde6bfea2238c Mon Sep 17 00:00:00 2001 From: Mike Bayer Date: Sun, 5 Jan 2014 16:57:05 -0500 Subject: - happy new year --- lib/sqlalchemy/orm/loading.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'lib/sqlalchemy/orm/loading.py') diff --git a/lib/sqlalchemy/orm/loading.py b/lib/sqlalchemy/orm/loading.py index dfb8f11a8..af77fe3e0 100644 --- a/lib/sqlalchemy/orm/loading.py +++ b/lib/sqlalchemy/orm/loading.py @@ -1,5 +1,5 @@ # orm/loading.py -# Copyright (C) 2005-2013 the SQLAlchemy authors and contributors +# Copyright (C) 2005-2014 the SQLAlchemy authors and contributors # # This module is part of SQLAlchemy and is released under # the MIT License: http://www.opensource.org/licenses/mit-license.php -- cgit v1.2.1