Adam Dziendziel wrote:
> On 28 Gru, 20:19, "Michael Bayer" <mike...@zzzcomputing.com> wrote:
>>
>> query.get() doesn't work with filtering criterion.  This because it
>> looks
>> up in the current session by primary key, and if present issues no SQL.
>> If it were filtered, you'd get different results based on whether or not
>> the object were already loaded or not.    It actually should be raising
>> an
>> error as get() should be asserting that no existing filter criterion is
>> set up.
>
> Have you considered making get(*primary_key_as_list) a synonym for
> filter_by(**primary_key_as_dict)? Then if a filtering criterion
> contains only a primary key, do a look up in the session.

A query in the general can be against any number of individual columns,
mapped entities, or aggregate functions.   It can be selecting from many
tables at once, as well as from other Query objects as subqueries.  
Trying to guess if filter_by() happens to be selecting exactly a single
row primary key from all of that seems complicated.   It would also be a
surprise that it very occasionally pulls from cache, but in most cases not
- all based on the particular structure of a query.

If filter_by() did do that, in this specific case it still would not pull
from cache since the criterion would be against more than just the primary
key columns.   I'd say the direction here is to not use get() if you would
like any filtering to be applied, including from this new option.

If you're looking for general caching of results, that's a different
issue.  There are some recipes for that in examples/.




>
>
> --
>
> You received this message because you are subscribed to the Google Groups
> "sqlalchemy" group.
> To post to this group, send email to sqlalch...@googlegroups.com.
> To unsubscribe from this group, send email to
> sqlalchemy+unsubscr...@googlegroups.com.
> For more options, visit this group at
> http://groups.google.com/group/sqlalchemy?hl=en.
>
>
>

--

You received this message because you are subscribed to the Google Groups 
"sqlalchemy" group.
To post to this group, send email to sqlalch...@googlegroups.com.
To unsubscribe from this group, send email to 
sqlalchemy+unsubscr...@googlegroups.com.
For more options, visit this group at 
http://groups.google.com/group/sqlalchemy?hl=en.


Reply via email to