Skip to content

Fix total_entries inflation in GET /api/v2/importErrors when file has multiple DAGs#67640

Open
GayathriSrividya wants to merge 3 commits into
apache:mainfrom
GayathriSrividya:fix/import-error-total-entries-67525
Open

Fix total_entries inflation in GET /api/v2/importErrors when file has multiple DAGs#67640
GayathriSrividya wants to merge 3 commits into
apache:mainfrom
GayathriSrividya:fix/import-error-total-entries-67525

Conversation

@GayathriSrividya
Copy link
Copy Markdown

When a single import-error file mapped to N DAGs, `GET /api/v2/importErrors` returned an inflated `total_entries` (N× the real count) and incorrect pagination behaviour.

Root cause: The query JOINed `ParseImportError` with `file_dags_cte` (one row per DAG per file), producing N rows per import error. `paginated_select` counted those N rows and applied `LIMIT`/`OFFSET` against joined rows rather than distinct import-error objects.

Fix: Two-query approach:

  1. `dedup_stmt` with `.distinct()` — one row per import error — fed to `paginated_select` for correct `total_entries` and pagination.
  2. `import_errors_stmt` — full JOIN restricted to the paginated IDs only — used to gather `dag_id` associations for auth checks and stacktrace redaction.

Tests: Added regression test `test_total_entries_counts_distinct_import_errors_when_file_has_multiple_dags` that creates one `ParseImportError` with three associated `DagModel` rows and asserts `total_entries == 1` and the list endpoint returns exactly one entry with `limit=1`.

closes: #67525


Was generative AI tooling used to co-author this PR?
  • Yes — GitHub Copilot (Claude Sonnet 4.6)

Generated-by: GitHub Copilot (Claude Sonnet 4.6) following the guidelines

@boring-cyborg
Copy link
Copy Markdown

boring-cyborg Bot commented May 28, 2026

Congratulations on your first Pull Request and welcome to the Apache Airflow community! If you have any issues or are unsure about any anything please check our Contributors' Guide
Here are some useful points:

  • Pay attention to the quality of your code (ruff, mypy and type annotations). Our prek-hooks will help you with that.
  • In case of a new feature add useful documentation (in docstrings or in docs/ directory). Adding a new operator? Check this short guide Consider adding an example Dag that shows how users should use it.
  • Consider using Breeze environment for testing locally, it's a heavy docker but it ships with a working Airflow and a lot of integrations.
  • Be patient and persistent. It might take some time to get a review or get the final approval from Committers.
  • Please follow ASF Code of Conduct for all communication including (but not limited to) comments on Pull Requests, Mailing list and Slack.
  • Be sure to read the Airflow Coding style.
  • Always keep your Pull Requests rebased, otherwise your build might fail due to changes not related to your commits.
    Apache Airflow is a community-driven project and together we are making it better 🚀.
    In case of doubts contact the developers at:
    Mailing List: dev@airflow.apache.org
    Slack: https://s.apache.org/airflow-slack

@@ -0,0 +1 @@
Fixed ``total_entries`` inflation in ``GET /api/v2/importErrors`` when one file contains multiple DAGs.
Copy link
Copy Markdown
Contributor

@Pedrinhonitz Pedrinhonitz May 28, 2026

Choose a reason for hiding this comment

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

We don't need this for this type of correction; please remove or revert. Check newsfragment PR number / check-newsfragment-pr-number (pull_request)

Please also ensure that all quality tests are completed successfully. (Tests (AMD) / CI image checks / Static checks (pull_request))

Gayathri Srividya Rajavarapu added 3 commits May 30, 2026 17:53
… multiple DAGs

When a single import-error file mapped to N DAGs, the previous query
JOINed ParseImportError with file_dags_cte producing N rows per error.
paginated_select then counted those N rows, inflating total_entries and
applying LIMIT/OFFSET against joined rows rather than distinct errors.

Fix uses a two-query approach:
1. dedup_stmt with DISTINCT - one row per import error for correct count
   and pagination via paginated_select
2. import_errors_stmt - full join only for the paginated IDs to gather
   dag_id associations for authorization/stacktrace redaction

Closes apache#67525
@GayathriSrividya GayathriSrividya force-pushed the fix/import-error-total-entries-67525 branch from 92898f2 to 5fbc84e Compare May 30, 2026 12:24
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

area:API Airflow's REST/HTTP API

Projects

None yet

Development

Successfully merging this pull request may close these issues.

/api/v2/importErrors inflates total_entries when one import-error file maps to multiple DAGs

2 participants