Commits

Mike Bayer committed 31be048

make Query._clone() class-agnostic

  • Participants
  • Parent commits d4afca1

Comments (0)

Files changed (3)

File examples/query_caching/query_caching.py

     def with_cache_key(self, cachekey):
         self.cachekey = cachekey
 
-    # override the _clone() method.   a future release
-    # will just fix _clone() in Query to not hardcode the class so this won't be needed.
-    def _clone(self):
-        q = CachingQuery.__new__(CachingQuery)
-        q.__dict__ = self.__dict__.copy()
-        return q
-
     # single point of object loading is __iter__().  objects in the cache are not associated
     # with a session and are never returned directly; only merged copies.
     def __iter__(self):

File lib/sqlalchemy/orm/query.py

         return self
 
     def _clone(self):
-        q = Query.__new__(Query)
+        cls = self.__class__
+        q = cls.__new__(cls)
         q.__dict__ = self.__dict__.copy()
         return q
 

File lib/sqlalchemy/orm/shard.py

         self.query_chooser = self.session.query_chooser
         self._shard_id = None
         
-    def _clone(self):
-        q = ShardedQuery.__new__(ShardedQuery)
-        q.__dict__ = self.__dict__.copy()
-        return q
-    
     def set_shard(self, shard_id):
         """return a new query, limited to a single shard ID.