On Tue, Oct 22, 2019, at 12:08 PM, eric.lemo...@gmail.com wrote:
> 
> 
> On Tue, Oct 22, 2019 at 5:59 PM Mike Bayer <mike...@zzzcomputing.com> wrote:
>> 
>> 
>> On Tue, Oct 22, 2019, at 11:58 AM, Eric Lemoine wrote:
>>> 
>>> 
>>>>> The first time before_compile is called twice, one call for the SELECT 
>>>>> FROM "user" query, and another call for the SELECT FROM "address" query. 
>>>>> But the second time before_compile is called only once. It's called for 
>>>>> the SELECT FROM "user" query, but not for the SELECT FROM "addresses" 
>>>>> query. Is it expected?
>>>>> 
>>>>> I am using SQLAlchemy 1.3.10.
>>>> 
>>>> sure, it sounds like u.addresses is already loaded. if you want 
>>>> u.addresses to emit a query every time it is called you need to use the 
>>>> "dynamic" loader strategy, that is, lazy="dynamic".
>>> 
>>> 
>>> I think the problem is related to "baked queries". I don't have the problem 
>>> with enable_baked_queries set to False in sessionmaker.
>> 
>> oh right that too, those queries are cached. but whatever changes you made 
>> to the query should also be cached, how come you need it to be different 
>> every time?
> 
> 
> I have HTTP queries with authenticated users associated to tenants. And I 
> wanted to use the Filtered Query pattern to only select objects bound to the 
> current tenant, without having to write complex queries (with explicit 
> filters for the current tenant) in the request handling code. But that 
> doesn't work, because of that "baked queries" issue. The Filtered Query 
> example in the wiki page works because the filter is fixes (obj.public == 
> True). In my case I want something like obj.tenant_id == 
> get_tenant_id_from_request().

it sounds like you should use a bound parameter with a lambda inside of it, 
there's not an explicit "on lazyload" hook at the moment. but yeah turn off the 
baked queries does it too


> 
> Thanks Mike.
> 
> -- 
> Eric
> 

> --
>  SQLAlchemy - 
>  The Python SQL Toolkit and Object Relational Mapper
> 
> http://www.sqlalchemy.org/
> 
>  To post example code, please provide an MCVE: Minimal, Complete, and 
> Verifiable Example. See http://stackoverflow.com/help/mcve for a full 
> description.
>  --- 
>  You received this message because you are subscribed to the Google Groups 
> "sqlalchemy" group.
>  To unsubscribe from this group and stop receiving emails from it, send an 
> email to sqlalchemy+unsubscr...@googlegroups.com.
>  To view this discussion on the web visit 
> https://groups.google.com/d/msgid/sqlalchemy/CAEE1YngiAsqqUwFJAaHZC0pj%3DU0pUtfGtEA2UPxv0toaCNcEwg%40mail.gmail.com
>  
> <https://groups.google.com/d/msgid/sqlalchemy/CAEE1YngiAsqqUwFJAaHZC0pj%3DU0pUtfGtEA2UPxv0toaCNcEwg%40mail.gmail.com?utm_medium=email&utm_source=footer>.

-- 
SQLAlchemy - 
The Python SQL Toolkit and Object Relational Mapper

http://www.sqlalchemy.org/

To post example code, please provide an MCVE: Minimal, Complete, and Verifiable 
Example.  See  http://stackoverflow.com/help/mcve for a full description.
--- 
You received this message because you are subscribed to the Google Groups 
"sqlalchemy" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to sqlalchemy+unsubscr...@googlegroups.com.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/sqlalchemy/2e7c4d57-96d0-490b-a2f3-946fd3a201f5%40www.fastmail.com.

Reply via email to