diff options
author | Mike Bayer <mike_mp@zzzcomputing.com> | 2022-12-18 16:33:22 -0500 |
---|---|---|
committer | Mike Bayer <mike_mp@zzzcomputing.com> | 2022-12-26 13:48:55 -0500 |
commit | 4338213935b4133e36d593ceec75f7fe36c13f66 (patch) | |
tree | 526982c75061dfe2fea8d0c0f5093a4ebdadf587 /examples/sharding/separate_databases.py | |
parent | ce8c0013169bdbe377ca21389f85051525814264 (diff) | |
download | sqlalchemy-4338213935b4133e36d593ceec75f7fe36c13f66.tar.gz |
reorganize pre_session_exec around do_orm_execute
Allow do_orm_execute() events to both receive the complete
state of bind_argments, load_options, update_delete_options
as they do already, but also allow them to *change* all those
things via new execution options. Options like autoflush,
populate_existing etc. can now be updated within a
do_orm_execute() hook and those changes will take effect
all the way through.
Took a few tries to get something that covers every case here,
in particular horizontal sharding which is consuming those
options as well as using context.invoke(), without excess
complexity. The good news seems to be that a simple
reorg and replacing the "reentrant" boolean with
"is this before do_orm_execute is invoked" was all that was
needed.
As part of this we add a new "identity_token" option allowing
this option to be controlled from do_orm_execute() as well
as from the outside.
WIP
Fixes: #7837
Change-Id: I087728215edec8d1b1712322ab389e3f52ff76ba
Diffstat (limited to 'examples/sharding/separate_databases.py')
-rw-r--r-- | examples/sharding/separate_databases.py | 10 |
1 files changed, 5 insertions, 5 deletions
diff --git a/examples/sharding/separate_databases.py b/examples/sharding/separate_databases.py index a45182f42..fe92fd3ba 100644 --- a/examples/sharding/separate_databases.py +++ b/examples/sharding/separate_databases.py @@ -135,8 +135,8 @@ def shard_chooser(mapper, instance, clause=None): return shard_chooser(mapper, instance.location) -def id_chooser(query, ident): - """id chooser. +def identity_chooser(mapper, primary_key, *, lazy_loaded_from, **kw): + """identity chooser. given a primary key, returns a list of shards to search. here, we don't have any particular information from a @@ -145,11 +145,11 @@ def id_chooser(query, ident): distributed among DBs. """ - if query.lazy_loaded_from: + if lazy_loaded_from: # if we are in a lazy load, we can look at the parent object # and limit our search to that same shard, assuming that's how we've # set things up. - return [query.lazy_loaded_from.identity_token] + return [lazy_loaded_from.identity_token] else: return ["north_america", "asia", "europe", "south_america"] @@ -237,7 +237,7 @@ def _get_select_comparisons(statement): # further configure create_session to use these functions Session.configure( shard_chooser=shard_chooser, - id_chooser=id_chooser, + identity_chooser=identity_chooser, execute_chooser=execute_chooser, ) |