Skip to content

Show error in UI when a DAG with same dag_id as another DAG is present - #17891

Closed
siddharthvp wants to merge 5 commits into
apache:mainfrom
siddharthvp:dupe-id-error
Closed

siddharthvp wants to merge 5 commits into
apache:mainfrom
siddharthvp:dupe-id-error

Conversation

@siddharthvp

Copy link
Copy Markdown

While the exception (AirflowDagDuplicatedIdException) already
existed, till now it was being raised only when both the DAGs with
same ID were in the same file.

Closes #17861.


^ Add meaningful description above

Read the Pull Request Guidelines for more information.
In case of fundamental code change, Airflow Improvement Proposal (AIP) is needed.
In case of a new dependency, check compliance with the ASF 3rd Party License Policy.
In case of backwards incompatible changes please leave a note in UPDATING.md.

@boring-cyborg

boring-cyborg Bot commented Aug 29, 2021

Copy link
Copy Markdown

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 Contribution Guide (https://github.com/apache/airflow/blob/main/CONTRIBUTING.rst)
Here are some useful points:

  • Pay attention to the quality of your code (flake8, mypy and type annotations). Our pre-commits 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.
    Apache Airflow is a community-driven project and together we are making it better 🚀.
    In case of doubts contact the developers at:
    Mailing List: [email protected]
    Slack: https://s.apache.org/airflow-slack

Comment thread airflow/models/dagbag.py Outdated

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

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

Using fileloc_hash here as that's an indexed column so should be faster to query, though this does necessitate computing the hash of the current dag's fileloc.

Comment thread airflow/models/dagbag.py Outdated
Comment on lines 488 to 500

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

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

I'm assuming that we don't actually want to re-parse that other file to see if the same-id-DAG is still present.

If the two DAGs have the same number and IDs of tasks, the error is suppressed as it's possible it's the same DAG just moved from one file to another. This is awful - is there a better heuristic we can use?

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.

If it was just a file rename, it would go away on the next scan, right? Can we pend the error immediately but only show it to the user if it is still the case later on?

@uranusjr

Copy link
Copy Markdown
Member

This logic feels hacky to me. Even if the numbers of tasks are not the same, we can’t be sure it’s a duplicated ID either; the user might have renamed the file and made some modification. I think this is theoratically impossible to fix in the current structure.

To really resolve this, we need a place to actually aggregate all the known DAG IDs during a DAG-parsing run. One possibility is to implement something like a standalone process exposing a message queue for every DAG-parsing process to send parsed DAG IDs to, and raises an error if it seems duplication.

Another possibility is, instead of storing parsed DAGs directly to SerialiazedDagModel, DAG-parsing processes should save things to a different tables (say ParsingDagModel) when they are running. This table would be empty when a DAG-parsing round starts, so any duplicated IDs are guaranteed to be real duplication (barring some filesystem race condition edge cases which we don’t currently cover anyway). After all the parsing processes successfully finish parsing this round (without reporting duplication, this ParsingDagModel is dumped into SerializedDagModel and truncated for the next parsing round.

Both would require some pretty involved change though.

@siddharthvp

siddharthvp commented Aug 30, 2021 •

Copy link
Copy Markdown
Author

Yes the logic is indeed hacky.

@uranusjr Even with the two solutions you suggest, the problem doesn't really go away (unless I'm much mistaken) - if a DAG is moved from one file to another in the middle of a parsing run and Airflow processed the source file before the move occurred and the destination file after the move, we still have a false-positive error.

So I think the only way to implement this feature would be via hacky heuristics. Maybe we should also change the exception text to clarify that it is a possible duplication. When the next DAG parsing run occurs, the false-positive alert would disappear.

Comment thread airflow/models/dagbag.py Resolved
Comment thread airflow/models/dagbag.py Resolved
Comment thread airflow/models/dagbag.py Outdated

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.

If these two lists are built from the same DAG, will they always be in the same order? If not then the comparison isn't going to be accurate.

If they aren't in a deterministic order, maybe we could sort or cast to a set before comparison?

siddharthvp and others added 5 commits September 2, 2021 01:53
While the exception (`AirflowDagDuplicatedIdException`) already
existed, till now it was being raised only when both the DAGs with
same ID were in the same file.

Closes apache#17861.
Co-authored-by: Ephraim Anierobi <[email protected]>
@github-actions

Copy link
Copy Markdown
Contributor

This pull request has been automatically marked as stale because it has not had recent activity. It will be closed in 5 days if no further activity occurs. Thank you for your contributions.

@github-actions github-actions Bot added the stale Stale PRs per the .github/workflows/stale.yml policy file label Oct 17, 2021
@github-actions github-actions Bot closed this Oct 22, 2021
@uranusjr uranusjr mentioned this pull request Nov 24, 2021
1 of 2 tasks
@kaxil kaxil reopened this Nov 26, 2021
@kaxil kaxil removed the stale Stale PRs per the .github/workflows/stale.yml policy file label Nov 26, 2021
@github-actions

Copy link
Copy Markdown
Contributor

This pull request has been automatically marked as stale because it has not had recent activity. It will be closed in 5 days if no further activity occurs. Thank you for your contributions.

@github-actions github-actions Bot added the stale Stale PRs per the .github/workflows/stale.yml policy file label Jan 11, 2022
@github-actions github-actions Bot closed this Jan 17, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

stale Stale PRs per the .github/workflows/stale.yml policy file

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Print error in Airflow UI when a DAG with duplicate DAG_id as another DAG is present

6 participants