]> git.ipfire.org Git - thirdparty/sqlalchemy/sqlalchemy.git/commitdiff
Include bulk update/delete in RoutingSession example
authorMike Bayer <mike_mp@zzzcomputing.com>
Fri, 7 Aug 2020 16:32:50 +0000 (12:32 -0400)
committerMike Bayer <mike_mp@zzzcomputing.com>
Fri, 7 Aug 2020 16:32:50 +0000 (12:32 -0400)
Fixes: #5407
Change-Id: Ia0965dbc88d744cded5c23021898388f2cf95f8d

doc/build/orm/persistence_techniques.rst

index 226b318373845db39a7b3d79fa42205adf5eb6dd..ffafe92958c3d1731c78700432573b5acb308774 100644 (file)
@@ -706,7 +706,8 @@ More comprehensive rule-based class-level partitioning can be built by
 overriding the :meth:`.Session.get_bind` method.   Below we illustrate
 a custom :class:`.Session` which delivers the following rules:
 
-1. Flush operations are delivered to the engine named ``leader``.
+1. Flush operations, as well as bulk "update" and "delete" operations,
+   are delivered to the engine named ``leader``.
 
 2. Operations on objects that subclass ``MyOtherClass`` all
    occur on the ``other`` engine.
@@ -723,6 +724,7 @@ a custom :class:`.Session` which delivers the following rules:
         'follower2':create_engine("sqlite:///follower2.db"),
     }
 
+    from sqlalchemy.sql import Update, Delete
     from sqlalchemy.orm import Session, sessionmaker
     import random
 
@@ -730,7 +732,7 @@ a custom :class:`.Session` which delivers the following rules:
         def get_bind(self, mapper=None, clause=None):
             if mapper and issubclass(mapper.class_, MyOtherClass):
                 return engines['other']
-            elif self._flushing:
+            elif self._flushing or isinstance(clause, (Update, Delete)):
                 return engines['leader']
             else:
                 return engines[