-
Notifications
You must be signed in to change notification settings - Fork 1k
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
SQLAlchemy 2.0 upgrades (part 4) #16852
Conversation
9340b20
to
1824d65
Compare
1956de1
to
3954230
Compare
8735f50
to
2c9d657
Compare
Converting to draft. While working on a related session issue caught a failing API test that only happens locally and is SA-related. I don't understand (yet) why it has always passed remotely, so marking this as draft until l figure this out and can verify it works correctly. |
Yes, so it happens on sqlite only: |
Can't call union() more than once because on second call we have a CompoundSelect. Reversing stmt with all-stmts will result in improper nesting. Proposed fix solves this: we collect Select statements into a list, then union the first item with the rest. The list is guaranteed to have at least one item.
Refactor: use native SA one_or_none method instead of calling self._one_or_none >> self._one_with_recast_errors. Reason: old code duplicated SA's error catching logic while not providing a useful error message. Using SA's native method achieves the same result with a more useful error message and without adding custom code. The _one_or_none method is dropped as it is not used anywhere else.
We don't need eagerloads(False): it's an `exists` statement; there were no joins in the first place.
Add forms manager module for FormDefinition/FormDefintionCurrent data access functions.
Reuse slug_exists function
2c9d657
to
2fa96df
Compare
I've removed 2 commits which handled the The solution is relatively simple, but requires some refactoring that, I feel, belongs in a separate PR (it's a different type of fix-up compared to what's done here (which is to only upgrade to SA2.0). SQL generated by the Select object: SELECT job.id, job.create_time, ...
FROM job ...
UNION
SELECT job.id, job.create_time, ...
FROM job ...
ORDER BY create_time DESC -- this breaks SQL generated by the legacy Query object: SELECT
anon_1.job_id AS anon_1_job_id,
anon_1.job_create_time AS anon_1_job_create_time, ...
FROM
(
SELECT
job.id AS job_id,
job.create_time AS job_create_time, ...
FROM job ...
UNION
SELECT
job.id AS job_id,
job.create_time AS job_create_time, ...
FROM job ...
ORDER BY
anon_1.job_create_time DESC -- this works fine |
) | ||
return bool(self.session().execute(stmt).first()) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Seems like an exists would be marginally better ?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yes, and easier to read too! I'll add this to the next batch (#16932).
Thanks for reviewing!
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Addressed in 7769ddc.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Looks great, thank you!
SQLAlchemy 2.0 compatibility upgrades. Ref #12541.
This covers the
managers/
directory, with just a few cases left out (inbase
,history_contents
andsharable
- those involve query-building abstractions which may require more refactoring; I'll have a separate PR for those). All commits are atomic; most are straightforward syntactical edits. If there is a notable refactoring present, I noted that in the commit description.How to test the changes?
(Select all options that apply)
License