summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorMike Bayer <mike_mp@zzzcomputing.com>2015-06-03 10:08:33 -0400
committerMike Bayer <mike_mp@zzzcomputing.com>2015-06-03 10:08:33 -0400
commit47d29eae8fa14ab7b1aab63797860a475338f950 (patch)
tree47a386c0fa1a32e455ea72cfad46cb4a59df8446
parent36d2b40cf55bc0f4e850e9ec4e905f0051f573f2 (diff)
downloadsqlalchemy-47d29eae8fa14ab7b1aab63797860a475338f950.tar.gz
- changelog for pr bitbucket:54
- alter the approach so that the initial callable is working just like add_criteria/with_criteria
-rw-r--r--doc/build/changelog/changelog_10.rst10
-rw-r--r--lib/sqlalchemy/ext/baked.py9
-rw-r--r--test/ext/test_baked.py20
3 files changed, 33 insertions, 6 deletions
diff --git a/doc/build/changelog/changelog_10.rst b/doc/build/changelog/changelog_10.rst
index 038b5b4da..63f2c797f 100644
--- a/doc/build/changelog/changelog_10.rst
+++ b/doc/build/changelog/changelog_10.rst
@@ -19,6 +19,16 @@
: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
diff --git a/lib/sqlalchemy/ext/baked.py b/lib/sqlalchemy/ext/baked.py
index 96e1f1312..f01e0b348 100644
--- a/lib/sqlalchemy/ext/baked.py
+++ b/lib/sqlalchemy/ext/baked.py
@@ -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
diff --git a/test/ext/test_baked.py b/test/ext/test_baked.py
index 92ce45c3f..78c43fc7e 100644
--- a/test/ext/test_baked.py
+++ b/test/ext/test_baked.py
@@ -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