]> 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:33:31 +0000 (12:33 -0400)
Fixes: #5407
Change-Id: Ia0965dbc88d744cded5c23021898388f2cf95f8d
(cherry picked from commit 7f52c10357cbc98e467f317128b3fea2018eaf7c)

doc/build/orm/persistence_techniques.rst

index 8aa0da9c8a0143e6467d88f4438d4aa68853986e..76111f15f94ad98c09105c2bd62135923eaa435c 100644 (file)
@@ -591,7 +591,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.
@@ -608,6 +609,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
 
@@ -615,7 +617,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[