-
Notifications
You must be signed in to change notification settings - Fork 14.2k
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
Show Deprecation warning on duplicate Task ids #8728
Conversation
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Looks good overall. Basically two things worth noting.
- A few naming ambiguities in the tests that could be clarified.
- The tests are currently testing the content of warning message strings. This is making them brittle.
tests/models/test_dag.py
Outdated
PendingDeprecationWarning, | ||
"The requested task could not be added to the DAG because a task with " | ||
"task_id t1 is already in the DAG. Starting in Airflow 2.0, trying to " | ||
"overwrite a task will raise an exception." |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Testing for the exact response message is likely to make this case brittle. Here are some possible alternatives:
- Create a class constant on Dag that stores this string, and use it both in the implementation and the test.
- Same as 1, but instead put it in a
warnings.py
file or similar. - Same as 1, but add some type of Warning or Alert mixin.
- Create a child class of
PendingDeprecationWarning
that encompasses the message body, then just text for the Exception type. - Only modify the test and check for the presence of
t1
and2.0
.
4 probably makes the most sense. Can add 5 to it for extra safety that string interpolation is working.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The main reason we test for the exact same message is otherwise, even if someone changes the message in warnings.py the test would still pass.
CI failures are unrelated. @potiuk any idea? |
Will be fixed by #8758 |
airflow/models/baseoperator.py
Outdated
@@ -546,7 +546,8 @@ def dag(self, dag): | |||
"The DAG assigned to {} can not be changed.".format(self)) | |||
elif self.task_id not in dag.task_dict: | |||
dag.add_task(self) | |||
|
|||
elif self.task_id in dag.task_dict and dag.task_dict[self.task_id] != self: |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Do we want dag.task_dict[self.task_id] != self
, or dag.task_dict[self.task_id] is not self
.
The former use __eq__
, the later checks for exactly the same object.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Updated, I will update Airflow Master as we currently raise errors after ==
check
Only cos it's related to this PR, not that it's a bug with this PR And I think I've just found a problem in our example dags caused by us using airflow/airflow/providers/google/cloud/example_dags/example_gcs.py Lines 129 to 130 in 6e4f5fa
|
@kaxil this is causing issue for me if i have same taskid in 2 different dags |
It should not show you warning for different dags, unless you are using context manager and have |
@kaxil I use context manager and |
You are right, in theory it should not, although I roughly remember I had to change:
to
Can't remember why and when though |
We already raise the warning at https://github.com/apache/airflow/blob/1.10.10/airflow/models/dag.py#L1318-L1328 but that wasn't enough.
We raise an error for Airflow 2.0 . PR where we did that: https://github.com/apache/airflow/pull/6549/files
Before:
After:
Make sure to mark the boxes below before creating PR: [x]
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.
Read the Pull Request Guidelines for more information.