Repository navigation
Sub-select with ORM object changes in ORM-touching sub-select doesn't cause flush? #9804
Unanswered
igorham000
asked this question in
Usage Questions
Replies: 1 comment
|
I've added #9804 for this which will use ORM contexts for all statements that have any ORM attributes anywhere within them. This might be too heavy-handed of a change depending on how the tests/ review go. Ultimately, "autoflush" would be turned on for all statements within session.execute(), but this would be too big a change for 2.0.x. |
0 replies
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Uh oh!
There was an error while loading. Please reload this page.
I was debugging a hybrid_attribute on an orm'd class, and was getting strange results. The query was basically a simple select of a specific row of one table, with the only column being a sub-select grabbing a corresponding element on a different table - phrased as a sub-select to deal with a group-by clause. Something like
After poking around a bit, I found out it was because the ORM session wasn't flushing before query execution. I found this line seemed to be the key (orm/sessions.py:2027)

which, in something like

SELECT a.id FROM a, causes the if branch on sessons.py:2097 to return True, causing the session to flush.In the unhappy path - e.g. queries like above - the compile_state_cls is None because the "orm" plugin wasn't found in that first if statement, even though it's set in the sub-select.
To reproduce what I'm seeing:
Not really clear on the rules around flushing, or if this is expected behavior - the code suggested they were more nuanced than "flush before every query execution", but that's what the docs I found suggested to be the case 🤔
Tested on postgres against versions 2.0.13 & 2.0.14
All reactions