-
Notifications
You must be signed in to change notification settings - Fork 14.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
Refactor sqlalchemy queries to 2.0 style (Part 1) #31569
Refactor sqlalchemy queries to 2.0 style (Part 1) #31569
Conversation
ec72e1e
to
0994ff2
Compare
872d853
to
334ebeb
Compare
airflow/api/common/mark_tasks.py
Outdated
tis = session.execute( | ||
select(TaskInstance).where( | ||
TaskInstance.dag_id == dag.dag_id, | ||
TaskInstance.run_id == run_id, | ||
TaskInstance.task_id.in_(task_ids), | ||
TaskInstance.state.in_([State.RUNNING, State.DEFERRED, State.UP_FOR_RESCHEDULE]), | ||
) | ||
) | ||
task_ids_of_running_tis = [task_instance.task_id for task_instance in tis] | ||
|
||
task_ids_of_running_tis = [task_instance.task_id for task_instance, in tis] |
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.
Note: This can be rewritten with scalars
on TaskInstance.task_id
instead. (Maybe in a later PR.)
46e0043
to
6708ec9
Compare
images/breeze/output_ci.svg
Outdated
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.
Hmm, it’s weird these screenshots are being updated. The added colouring also is suspective.
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.
I ran breeze setup regenerate-command-images --force
when I couldn't find why the PR was failing on pre-commit generating ER diagram(not locally)
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, what I was trying to say is I don’t understand why pre-commit thinks they need to be updated at all.
f369550
to
6722b44
Compare
dag_run = session.execute( | ||
select(DagRun).where(DagRun.dag_id == dag_id, DagRun.run_id == run_id) | ||
).scalar_one() |
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.
Should be equivalent to
dag_run = session.execute( | |
select(DagRun).where(DagRun.dag_id == dag_id, DagRun.run_id == run_id) | |
).scalar_one() | |
dag_run = session.scalars( | |
select(DagRun).where(DagRun.dag_id == dag_id, DagRun.run_id == run_id) | |
).one() |
but I don’t think this is better. So just for reference in case anyone wonders.
This commit updates the sqlalchemy queries to adopt the 2.0 query style, which is compatible with version 1.4. The changes involve updating the engine with the future=True flag to indicate the execution of queries using the 2.0 style. As a result, textual SQL statements are wrapped with the text function. In addition, queries that previously used delete and update operations have been modified to utilize the new delete/update construct. Furthermore, all queries within the jobs/ and api/ directories have been thoroughly updated to employ the new style queries. Please note that this commit intentionally stops at this point to ensure ease of review for the pull request. The only test change is the addition of the future flag to the create_engine function.
Co-authored-by: Tzu-ping Chung <[email protected]>
6722b44
to
c64be9f
Compare
This commit updates the sqlalchemy queries to adopt the 2.0 query style,
which is compatible with version 1.4. The changes involve updating the engine
with the future=True flag to indicate the execution of queries using the 2.0 style.
As a result, textual SQL statements are wrapped with the text function.
In addition, queries that previously used delete and update operations have been
modified to utilize the new delete/update construct. Furthermore, all queries within the
jobs/ and api/ directories have been thoroughly updated to employ the new style queries.
Please note that this commit intentionally stops at this point to ensure ease of review for the pull request.
The only test change is the addition of the future flag to the create_engine function.