diff options
author | Mike Bayer <mike_mp@zzzcomputing.com> | 2017-12-14 10:20:50 -0500 |
---|---|---|
committer | Mike Bayer <mike_mp@zzzcomputing.com> | 2017-12-22 11:36:53 -0500 |
commit | 50d9f1687a6e0c3ce9b62fe98b76b25af7b20c11 (patch) | |
tree | fec4931bac89e4706b45aa3ffdc82db30cfc9425 /lib/sqlalchemy/orm/loading.py | |
parent | 04937652f426e518781b2b762b0e0e8090857cbd (diff) | |
download | sqlalchemy-50d9f1687a6e0c3ce9b62fe98b76b25af7b20c11.tar.gz |
Add an identity_token to the identity key
For the purposes of assisting with sharded setups, add a new
member to the identity key that can be customized. this allows
sharding across databases where the primary key space is shared.
Change-Id: Iae3909f5d4c501b62c10d0371fbceb01abda51db
Fixes: #4137
Diffstat (limited to 'lib/sqlalchemy/orm/loading.py')
-rw-r--r-- | lib/sqlalchemy/orm/loading.py | 5 |
1 files changed, 4 insertions, 1 deletions
diff --git a/lib/sqlalchemy/orm/loading.py b/lib/sqlalchemy/orm/loading.py index a25a1422d..a23cafac2 100644 --- a/lib/sqlalchemy/orm/loading.py +++ b/lib/sqlalchemy/orm/loading.py @@ -369,6 +369,7 @@ def _instance_processor( session_id = context.session.hash_key version_check = context.version_check runid = context.runid + identity_token = context.identity_token if not refresh_state and _polymorphic_from is not None: key = ('loader', path.path) @@ -430,7 +431,8 @@ def _instance_processor( # session, or we have to create a new one identitykey = ( identity_class, - tuple([row[column] for column in pk_cols]) + tuple([row[column] for column in pk_cols]), + identity_token ) instance = session_identity_map.get(identitykey) @@ -464,6 +466,7 @@ def _instance_processor( dict_ = instance_dict(instance) state = instance_state(instance) state.key = identitykey + state.identity_token = identity_token # attach instance to session. state.session_id = session_id |