-
-
Notifications
You must be signed in to change notification settings - Fork 1.4k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Lazy='raise' seems overly aggressive and complains about the wrong field #7176
Comments
Hi, That's the expected documented behaviour. Session will return locally existing element if they are in the identity map. |
I see, thanks! |
Another alternative may be to expire @zzzeek we have had some other issues similar to this one, maybe we need some update to the docs? @RubeRuby do you have suggestions that would have helped in this case? |
For me it just wasn't clear that it would cache objects like this, since I am explicitly overwriting it with a new query. I don't know what the best place is to tell people though |
as mentioned elsewhere I want to get the Session to include a parameter so you can set up default execution options, then i want to start telling people maybe they want to turn on "populate_existing" for sessions right up front. there's not too much reason to not have this, with the caveat that we dont have a lot of experience having everyone do this such that we'd see what "reasons" there might be that we aren't aware of. |
@zzzeek ok. maybe a new issue makes sense as reminder |
revising my comment, in the example given they are using session.get(), and in that case i would hope the docs are pretty clear that this method does not emit SQL even for the primary entity if it's already present. if this were using session.execute(select()), that's where we tell folks to use the populate_existing execution option, but that doesnt apply to this method, which instead has a direct populate_existing pararameter.
@RubeRuby had you checked that documentation when you had this problem? does it explain why your test does what it does or is there something we can do to improve? |
I did read the documentation earlier but not in a targeted way for this issue, as the title of my (non) issue suggests I hadn't attributed it to |
Describe the bug
Let's say we have three models: a
User
,UserGroup
and anOrganization
.A user can belong to a
UserGroup
and needs to belong to anOrganization
. AUserGroup
needs to belong to the sameOrganization
as the user.I've specified
lazy='raise'
for all of the relationships because we use the async engine and so lazy loading is not possible.Now let's say we access
some_user_group.organization
through ajoinedload
but at the same time we accesssome_user.user_group
through ajoinedload
as well. This will result in the following error:sqlalchemy.exc.InvalidRequestError: 'UserGroup.organization' is not available due to lazy='raise'
The interesting part is that adding a joinedload with the organization for the user as well (so user->user_group->organization) fixes the problem. Even though I am not accessing that field. So it seems to complain without reason. I hope it becomes clear in the code sample
To Reproduce
Error
Versions
Additional context
No response
The text was updated successfully, but these errors were encountered: