summaryrefslogtreecommitdiff
path: root/lib/sqlalchemy/orm/loading.py
diff options
context:
space:
mode:
authorMike Bayer <mike_mp@zzzcomputing.com>2019-06-04 17:29:20 -0400
committerMike Bayer <mike_mp@zzzcomputing.com>2019-10-01 16:52:24 -0400
commitcc718cccc0bf8a01abdf4068c7ea4f32c9322af6 (patch)
treee839526dd0ab64bf0d8babe01006e03987403a66 /lib/sqlalchemy/orm/loading.py
parenta3c964203e61f8deeb559b15a78cc640dee67012 (diff)
downloadsqlalchemy-cc718cccc0bf8a01abdf4068c7ea4f32c9322af6.tar.gz
Run row value processors up front
as part of a larger series of changes to generalize row-tuples, RowProxy becomes plain Row and is no longer a "proxy"; the DBAPI row is now copied directly into the Row when constructed, result handling occurs at once. Subsequent changes will break out Row into a new version that behaves fully a tuple. Change-Id: I2ffa156afce5d21c38f28e54c3a531f361345dd5
Diffstat (limited to 'lib/sqlalchemy/orm/loading.py')
-rw-r--r--lib/sqlalchemy/orm/loading.py21
1 files changed, 10 insertions, 11 deletions
diff --git a/lib/sqlalchemy/orm/loading.py b/lib/sqlalchemy/orm/loading.py
index 94a9b8d22..53b901689 100644
--- a/lib/sqlalchemy/orm/loading.py
+++ b/lib/sqlalchemy/orm/loading.py
@@ -358,11 +358,6 @@ def _instance_processor(
# call overhead. _instance() is the most
# performance-critical section in the whole ORM.
- pk_cols = mapper.primary_key
-
- if adapter:
- pk_cols = [adapter.columns[c] for c in pk_cols]
-
identity_class = mapper._identity_class
populators = collections.defaultdict(list)
@@ -488,6 +483,12 @@ def _instance_processor(
else:
refresh_identity_key = None
+ pk_cols = mapper.primary_key
+
+ if adapter:
+ pk_cols = [adapter.columns[c] for c in pk_cols]
+ tuple_getter = result._tuple_getter(pk_cols, True)
+
if mapper.allow_partial_pks:
is_not_primary_key = _none_set.issuperset
else:
@@ -507,11 +508,7 @@ def _instance_processor(
else:
# look at the row, see if that identity is in the
# session, or we have to create a new one
- identitykey = (
- identity_class,
- tuple([row[column] for column in pk_cols]),
- identity_token,
- )
+ identitykey = (identity_class, tuple_getter(row), identity_token)
instance = session_identity_map.get(identitykey)
@@ -853,8 +850,10 @@ def _decorate_polymorphic_switch(
polymorphic_instances = util.PopulateDict(configure_subclass_mapper)
+ getter = result._getter(polymorphic_on)
+
def polymorphic_instance(row):
- discriminator = row[polymorphic_on]
+ discriminator = getter(row)
if discriminator is not None:
_instance = polymorphic_instances[discriminator]
if _instance: