From: Mike Bayer Date: Mon, 2 Jun 2008 15:32:17 +0000 (+0000) Subject: make Query._clone() class-agnostic X-Git-Tag: rel_0_5beta1~8 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=86ded90c6ee1b5ede09ed65b450e2918a2ba6d17;p=thirdparty%2Fsqlalchemy%2Fsqlalchemy.git make Query._clone() class-agnostic --- diff --git a/examples/query_caching/query_caching.py b/examples/query_caching/query_caching.py index 1ac8230b6c..fb250acca6 100644 --- a/examples/query_caching/query_caching.py +++ b/examples/query_caching/query_caching.py @@ -13,13 +13,6 @@ class CachingQuery(Query): 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): diff --git a/lib/sqlalchemy/orm/query.py b/lib/sqlalchemy/orm/query.py index 43f206f38a..700d24d33c 100644 --- a/lib/sqlalchemy/orm/query.py +++ b/lib/sqlalchemy/orm/query.py @@ -305,7 +305,8 @@ class Query(object): return self def _clone(self): - q = Query.__new__(Query) + cls = self.__class__ + q = cls.__new__(cls) q.__dict__ = self.__dict__.copy() return q diff --git a/lib/sqlalchemy/orm/shard.py b/lib/sqlalchemy/orm/shard.py index 6850a0bb07..b4525d8fbf 100644 --- a/lib/sqlalchemy/orm/shard.py +++ b/lib/sqlalchemy/orm/shard.py @@ -80,11 +80,6 @@ class ShardedQuery(Query): 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.