]> git.ipfire.org Git - thirdparty/sqlalchemy/sqlalchemy.git/commitdiff
- changelog for pr bitbucket:54
authorMike Bayer <mike_mp@zzzcomputing.com>
Wed, 3 Jun 2015 14:08:33 +0000 (10:08 -0400)
committerMike Bayer <mike_mp@zzzcomputing.com>
Wed, 3 Jun 2015 14:08:33 +0000 (10:08 -0400)
- alter the approach so that the initial callable is working just like add_criteria/with_criteria

doc/build/changelog/changelog_10.rst
lib/sqlalchemy/ext/baked.py
test/ext/test_baked.py

index 038b5b4da1a114a477f810728c27700c5e63f84d..63f2c797f8ddf44721f7f4766a0e3724b11eb57d 100644 (file)
 .. changelog::
     :version: 1.0.5
 
+    .. change::
+        :tags: feature, ext
+        :pullreq: bitbucket:54
+
+        Added support for ``*args`` to be passed to the baked query
+        initial callable, in the same way that ``*args`` are supported
+        for the :meth:`.BakedQuery.add_criteria` and
+        :meth:`.BakedQuery.with_criteria` methods.  Initial PR courtesy
+        Naoki INADA.
+
     .. change::
         :tags: bug, engine
         :tickets: 3435
index 96e1f1312f8c3adee2628d4b27815bde9dbda4a8..f01e0b348dcd22687f52609b559a184441f9d56f 100644 (file)
@@ -34,11 +34,8 @@ class BakedQuery(object):
     __slots__ = 'steps', '_bakery', '_cache_key', '_spoiled'
 
     def __init__(self, bakery, initial_fn, args=()):
-        if args:
-            self._cache_key = tuple(args)
-        else:
-            self._cache_key = ()
-        self._update_cache_key(initial_fn)
+        self._cache_key = ()
+        self._update_cache_key(initial_fn, args)
         self.steps = [initial_fn]
         self._spoiled = False
         self._bakery = bakery
@@ -49,7 +46,7 @@ class BakedQuery(object):
 
         _bakery = util.LRUCache(size)
 
-        def call(initial_fn, args=()):
+        def call(initial_fn, *args):
             return cls(_bakery, initial_fn, args)
 
         return call
index 92ce45c3f96bb150dd29d9ba5234467983cde0c4..78c43fc7e0e5a3c0eae2453400829a8c378e9d09 100644 (file)
@@ -242,6 +242,26 @@ class ResultTest(BakedTest):
         })
         mapper(Address, cls.tables.addresses)
 
+    def test_cachekeys_on_constructor(self):
+        User = self.classes.User
+
+        queue = [7, 8]
+        fn = lambda s: s.query(User.id).filter_by(id=queue.pop(0))
+        bq1 = self.bakery(fn, 7)
+        bq2 = self.bakery(fn, 8)
+
+        for i in range(3):
+            session = Session(autocommit=True)
+            eq_(
+                bq1(session).all(),
+                [(7,)]
+            )
+
+            eq_(
+                bq2(session).all(),
+                [(8,)]
+            )
+
     def test_no_steps(self):
         User = self.classes.User