I'm trying to extract SQLAlchemy query parameter values for use in caching, using the function _params_from_query
from the SQLAlchemy Beaker Caching example.
Unfortunately when I try it with a query involving a subquery, it seems to only traverse the main query parameters, ignoring the subquery.
The following example code demonstrates this when run from the beaker_cache
example folder in the SQLAlchemy distribution.
from environment import Session
from model import Person
from caching_query import _params_from_query
s = Session.query(Person.name).filter(Person.name=="subquery value").subquery()
q = Session.query(s.c.name).filter(s.c.name=="main query value")
print q.params()
print
print _params_from_query(q)
# SELECT anon_1.name AS anon_1_name
# FROM (SELECT person.name AS name
# FROM person
# WHERE person.name = :name_1) AS anon_1 <- two
# WHERE anon_1.name = :name_2 <- parameters
#
# ['main query value'] <- only one value
Am I using the function incorrectly? How can I get the parameter values from the subquery as well?