Skip to content

Cleanup: Enforce keyword-only session in db_cleanup#63781

Open
Gautam-Bharadwaj wants to merge 3 commits intoapache:mainfrom
Gautam-Bharadwaj:refactor-db-cleanup-session-standards
Open

Cleanup: Enforce keyword-only session in db_cleanup#63781
Gautam-Bharadwaj wants to merge 3 commits intoapache:mainfrom
Gautam-Bharadwaj:refactor-db-cleanup-session-standards

Conversation

@Gautam-Bharadwaj
Copy link
Copy Markdown
Contributor

Enforce keyword-only session parameters in db_cleanup utility functions and update tests to adhere to Airflow 3 standards.


Was generative AI tooling used to co-author this PR?
  • Yes

  • Read the Pull Request Guidelines for more information. Note: commit author/co-author name and email in commits become permanently public when merged.
  • For fundamental code changes, an Airflow Improvement Proposal (AIP) is needed.
  • When adding dependency, check compliance with the ASF 3rd Party License Policy.
  • For significant user-facing changes create newsfragment: {pr_number}.significant.rst, in airflow-core/newsfragments. You can add this file in a follow-up commit after the PR is created so you know the PR number.

@potiuk potiuk marked this pull request as draft March 17, 2026 12:07
@potiuk
Copy link
Copy Markdown
Member

potiuk commented Mar 17, 2026

@Gautam-Bharadwaj This PR has been converted to draft because it does not yet meet our Pull Request quality criteria.

Issues found:

  • Pre-commit / static checks: Failing: CI image checks / Static checks. Run prek run --from-ref main locally to find and fix issues. See Pre-commit / static checks docs.
  • mypy (type checking): Failing: CI image checks / MyPy checks (mypy-providers). Run prek --stage manual mypy-providers --all-files locally to reproduce. You need breeze ci-image build --python 3.10 for Docker-based mypy. See mypy (type checking) docs.
  • Other failing CI checks: Failing: check-newsfragment-pr-number. Run prek run --from-ref main locally to reproduce. See static checks docs.

Note: Your branch is 10 commits behind main. Some check failures may be caused by changes in the base branch rather than by your PR. Please rebase your branch and push again to get up-to-date CI results.

What to do next:

  • The comment informs you what you need to do.
  • Fix each issue, then mark the PR as "Ready for review" in the GitHub UI - but only after making sure that all the issues are fixed.
  • There is no rush — take your time and work at your own pace. We appreciate your contribution and are happy to wait for updates.
  • Maintainers will then proceed with a normal review.

Converting a PR to draft is not a rejection — it is an invitation to bring the PR up to the project's standards so that maintainer review time is spent productively. There is no rush — take your time and work at your own pace. We appreciate your contribution and are happy to wait for updates. If you have questions, feel free to ask on the Airflow Slack.

Gautam-Bharadwaj added a commit to Gautam-Bharadwaj/airflow that referenced this pull request Mar 17, 2026
@Gautam-Bharadwaj Gautam-Bharadwaj force-pushed the refactor-db-cleanup-session-standards branch from a4ae2eb to 0d93ce6 Compare March 17, 2026 14:40
@Gautam-Bharadwaj Gautam-Bharadwaj force-pushed the refactor-db-cleanup-session-standards branch from 0d93ce6 to d70044b Compare March 18, 2026 06:58
@Gautam-Bharadwaj Gautam-Bharadwaj marked this pull request as ready for review March 19, 2026 09:59
Copy link
Copy Markdown
Contributor

@SameerMesiah97 SameerMesiah97 left a comment

Choose a reason for hiding this comment

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

Technically, this is a breaking change but these 2 methods are internal APIs that are invoked in a handful of places. I have left a few comments. Please fix CI as well.

else:
confirm_mock.assert_not_called()

def test_export_archived_records_positional_fails(self):
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

I don't have a strong opinion against including these tests but aren't they just testing python's built-in behavior when * is added to the method signature?

*,
table_names: list[str] | None = None,
drop_archives: bool = False,
needs_confirm: bool = True,
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Why did you only make a subset of the parameters keyword-only for this method when you made all parameters for drop_archived_tables keyword-only?

Copy link
Copy Markdown
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

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

Pull request overview

This PR updates airflow.utils.db_cleanup utility functions to enforce keyword-only argument passing (notably for session) and adjusts unit tests and release notes accordingly.

Changes:

  • Made export_archived_records require keyword-only arguments after output_path (including session).
  • Made drop_archived_tables fully keyword-only (including table_names, needs_confirm, and session).
  • Updated unit tests and added a newsfragment documenting the behavior change.

Reviewed changes

Copilot reviewed 3 out of 3 changed files in this pull request and generated 2 comments.

File Description
airflow-core/src/airflow/utils/db_cleanup.py Updates function signatures to enforce keyword-only arguments.
airflow-core/tests/unit/utils/test_db_cleanup.py Updates callers to use keywords and adds tests asserting positional calls fail.
airflow-core/newsfragments/63781.improvement.rst Adds a release note about enforcing keyword-only parameters in db_cleanup.
Comments suppressed due to low confidence (1)

airflow-core/src/airflow/utils/db_cleanup.py:629

  • The new * placement makes all parameters after output_path keyword-only (not just session). If the intent (per PR title/description) is only to enforce keyword-only session, consider moving * to just before session so existing positional uses of table_names/drop_archives/needs_confirm keep working (and adjust the new “positional_fails” test accordingly).
def export_archived_records(
    export_format: str,
    output_path: str,
    *,
    table_names: list[str] | None = None,
    drop_archives: bool = False,
    needs_confirm: bool = True,
    session: Session = NEW_SESSION,
) -> None:

Comment on lines +656 to +658
*,
table_names: list[str] | None,
needs_confirm: bool,
Copy link

Copilot AI Apr 2, 2026

Choose a reason for hiding this comment

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

drop_archived_tables is now fully keyword-only (*, table_names, needs_confirm, session), which is a larger breaking change than “keyword-only session”. If you only need session to be keyword-only (per Airflow core guideline), you can keep table_names/needs_confirm positional-or-keyword and introduce *, session instead.

Suggested change
*,
table_names: list[str] | None,
needs_confirm: bool,
table_names: list[str] | None,
needs_confirm: bool,
*,

Copilot uses AI. Check for mistakes.
Comment on lines +745 to +752
with pytest.raises(TypeError) as exc:
export_archived_records("csv", "path", ["table"], True, True, None)
assert "takes 2 positional arguments but 6" in str(exc.value)

def test_drop_archived_tables_positional_fails(self):
with pytest.raises(TypeError) as exc:
drop_archived_tables(["table"], True)
assert "takes 0 positional arguments but 2" in str(exc.value)
Copy link

Copilot AI Apr 2, 2026

Choose a reason for hiding this comment

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

These tests assert on a specific CPython TypeError wording/argument count substring (e.g. "takes 2 positional arguments but 6"). The exact message format can vary across Python versions/implementations, making this brittle. Consider asserting only that a TypeError is raised, or use pytest.raises(..., match=...) with a looser regex that doesn’t depend on the exact count/message text.

Suggested change
with pytest.raises(TypeError) as exc:
export_archived_records("csv", "path", ["table"], True, True, None)
assert "takes 2 positional arguments but 6" in str(exc.value)
def test_drop_archived_tables_positional_fails(self):
with pytest.raises(TypeError) as exc:
drop_archived_tables(["table"], True)
assert "takes 0 positional arguments but 2" in str(exc.value)
with pytest.raises(TypeError, match="positional arguments"):
export_archived_records("csv", "path", ["table"], True, True, None)
def test_drop_archived_tables_positional_fails(self):
with pytest.raises(TypeError, match="positional arguments"):
drop_archived_tables(["table"], True)

Copilot uses AI. Check for mistakes.
@potiuk potiuk added the ready for maintainer review Set after triaging when all criteria pass. label Apr 2, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

ready for maintainer review Set after triaging when all criteria pass.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants