<h3 dir="auto">Apache Airflow version</h3>
<p dir="auto">2.5.1</p>
<h3 dir="auto">What happened</h3>
<p dir="auto">Create two files with DAGs<br>
Both DAGs must have the same ID<br>
Airflow will constantly update DAG structure/code resulting in dozens of weird behaviors and errors:</p>
<ul dir="auto">
<li>wrong DAG visualization</li>
<li>wrong DAG code</li>
<li>errors about missing tasks from time to time</li>
</ul>
<h3 dir="auto">What you think should happen instead</h3>
<p dir="auto">Airflow should show an error to the user and disable both DAGs.</p>
<h3 dir="auto">How to reproduce</h3>
<ol dir="auto">
<li>Create two files with DAGs</li>
<li>Both DAGs should have the same ID</li>
</ol>
<h3 dir="auto">Operating System</h3>
<p dir="auto">Ubuntu 22.04</p>
<h3 dir="auto">Versions of Apache Airflow Providers</h3>
<p dir="auto"><em>No response</em></p>
<h3 dir="auto">Deployment</h3>
<p dir="auto">Docker-Compose</p>
<h3 dir="auto">Deployment details</h3>
<p dir="auto"><em>No response</em></p>
<h3 dir="auto">Anything else</h3>
<p dir="auto"><em>No response</em></p>
<h3 dir="auto">Are you willing to submit PR?</h3>
<ul class="contains-task-list">
<li class="task-list-item"><input type="checkbox" id="" disabled="" class="task-list-item-checkbox"> Yes I am willing to submit a PR!</li>
</ul>
<h3 dir="auto">Code of Conduct</h3>
<ul class="contains-task-list">
<li class="task-list-item"><input type="checkbox" id="" disabled="" class="task-list-item-checkbox" checked=""> I agree to follow this project's <a href="https://github.com/apache/airflow/blob/main/CODE_OF_CONDUCT.md">Code of Conduct</a></li>
</ul>
<p dir="auto"><strong>Description</strong></p>
<p dir="auto">I would like to see an error in Airflow UI (like <code class="notranslate">"Broken DAG: duplicate DAG-id"</code>) when a DAG is present that has the same (non-unique) DAG-id as another DAG. Currently, Airflow silently ignores one of these duplicated DAGs.</p>
<p dir="auto"><strong>Use case / motivation</strong><br>
For users that either knowingly or unknowingly have multiple DAGs with the same DAG-id (which could happen especially in the case of dynamically generating DAGs), unintended/weird functionality can result as Airflow tries to figure out which DAG is the right one. It is not clear how Airflow will choose, and if that choice can change each time it parses for DAG changes.</p>
<p dir="auto"><strong>Additional Info</strong><br>
Currently in Airflow, my understanding is that the DAG file processor creates a new process and a new DagBag per file. As a result each DagBag only parses one DAG-script and thus DAGs with duplicate ids in different scripts are never detected. <a href="https://github.com/apache/airflow/blob/main/airflow/dag_processing/processor.py#L613">https://github.com/apache/airflow/blob/main/airflow/dag_processing/processor.py#L613</a></p>
<p dir="auto">Additionally, there's already a test and exception (<code class="notranslate">AirflowDagDuplicatedIdException</code>) in place for this, but it depends on a single DagBag having multiple DAGs in it, which isn't the case when actually running Airflow, from discussion with <a class="user-mention notranslate" data-hovercard-type="user" data-hovercard-url="/users/BasPH/hovercard" data-octo-click="hovercard-link-click" data-octo-dimensions="link_type:self" href="https://github.com/BasPH">@BasPH</a> and <a class="user-mention notranslate" data-hovercard-type="user" data-hovercard-url="/users/uranusjr/hovercard" data-octo-click="hovercard-link-click" data-octo-dimensions="link_type:self" href="https://github.com/uranusjr">@uranusjr</a>.<br>
<a href="https://github.com/apache/airflow/blob/2.1.3/airflow/models/dagbag.py#L405-L409">https://github.com/apache/airflow/blob/2.1.3/airflow/models/dagbag.py#L405-L409</a><br>
<a href="https://github.com/apache/airflow/blob/main/tests/models/test_dagbag.py#L143-L173">https://github.com/apache/airflow/blob/main/tests/models/test_dagbag.py#L143-L173</a></p>
<p dir="auto"><strong>Related Issues</strong></p>
<p dir="auto">I did not find other issues related to this, when searching for "duplicate DAG" or "duplicate DAG-id".</p>