Skip to content
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

Use COALESCE when ordering runs to handle NULL #26626

Merged
merged 1 commit into from Sep 26, 2022

Conversation

uranusjr
Copy link
Member

Data interval columns are NULL for runs created before 2.3, but SQL's NULL-sorting logic would make those old runs always appear first. In a perfect world we'd want to sort by get_run_data_interval(), but that's not efficient, so instead the columns are coalesced into logical date, which is good enough in most cases.

This should #26505, I think. Not sure if the UI side needs some additional work. cc @bbovenzi

Data interval columns are NULL for runs created before 2.3, but SQL's
NULL-sorting logic would make those old runs always appear first. In a
perfect world we'd want to sort by get_run_data_interval(), but that's
not efficient, so instead the columns are coalesced into logical date,
which is good enough in most cases.
@boring-cyborg boring-cyborg bot added the area:webserver Webserver related Issues label Sep 23, 2022
@ashb ashb added this to the Airflow 2.4.1 milestone Sep 23, 2022
dag_runs = query.order_by(*ordering, DagRun.id.desc()).limit(num_runs).all()
dag_runs.reverse()

dag_runs = wwwutils.sorted_dag_runs(query, ordering=dag.timetable.run_ordering, limit=num_runs)
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This feels more like it should be a method on DagRun class maybe? (That way this can be used by API or CLI too)

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This function in general includes some UI-specific sorting/slicing logic I don’t feel right making generic. The inner _get_run_ordering_expr probably should, but I’d rather wait until when we actually reuse it somewhere (we don’t right now).

@joshowen
Copy link
Contributor

Thank you for this change @uranusjr. I just confirmed this does fix #26505 in my dev environment (where the error was evident before the change).

@ashb ashb merged commit 22d52c0 into apache:main Sep 26, 2022
@ashb ashb deleted the fix-timetable-ordering-with-null branch September 26, 2022 12:59
jedcunningham pushed a commit that referenced this pull request Sep 26, 2022
Data interval columns are NULL for runs created before 2.3, but SQL's
NULL-sorting logic would make those old runs always appear first. In a
perfect world we'd want to sort by get_run_data_interval(), but that's
not efficient, so instead the columns are coalesced into logical date,
which is good enough in most cases.

(cherry picked from commit 22d52c0)
jedcunningham pushed a commit that referenced this pull request Sep 27, 2022
Data interval columns are NULL for runs created before 2.3, but SQL's
NULL-sorting logic would make those old runs always appear first. In a
perfect world we'd want to sort by get_run_data_interval(), but that's
not efficient, so instead the columns are coalesced into logical date,
which is good enough in most cases.

(cherry picked from commit 22d52c0)
@ephraimbuddy ephraimbuddy added the type:bug-fix Changelog: Bug Fixes label Oct 18, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
area:webserver Webserver related Issues type:bug-fix Changelog: Bug Fixes
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

4 participants