You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@airflow.apache.org by GitBox <gi...@apache.org> on 2021/01/03 11:42:32 UTC

[GitHub] [airflow] XD-DENG opened a new pull request #13449: Streamline & simplify __eq__ methods in models Dag and BaseOperator

XD-DENG opened a new pull request #13449:
URL: https://github.com/apache/airflow/pull/13449


   - Change-1: Use `getattr()` instead of __dict__ as __dict__ doesn't return correct values for properties (sample code reproducing the issue is given below). This was fixed for `dag` model, but was not fixed for `baseoperator` model.
   
   - Change-2: Avoid unnecessary condition check (the removed condition checks are covered by `_comps`)
   - Change-3: Use "==" rather than "is" to compare types (both work, but for more consistent usage)
   
   
   #### Sample Code Reproducing Issue in Change-1
   
   ```python
   class C:
   
       def __init__(self, elements):
           self._elements = elements
   
       @property
       def elements(self):
           return self._elements
   
       def test(self):
           print(self.__dict__.get("elements", None))
           print(getattr(self, "elements", None))
   
   a = C([1,2,3])
   a.test()
   ```
    Output:
   
   ```
   None
   [1, 2, 3]
   ```
   
   <!--
   Thank you for contributing! Please make sure that your code changes
   are covered with tests. And in case of new features or big changes
   remember to adjust the documentation.
   
   Feel free to ping committers for the review!
   
   In case of existing issue, reference it using one of the following:
   
   closes: #ISSUE
   related: #ISSUE
   
   How to write a good git commit message:
   http://chris.beams.io/posts/git-commit/
   -->
   
   ---
   **^ Add meaningful description above**
   
   Read the **[Pull Request Guidelines](https://github.com/apache/airflow/blob/master/CONTRIBUTING.rst#pull-request-guidelines)** for more information.
   In case of fundamental code change, Airflow Improvement Proposal ([AIP](https://cwiki.apache.org/confluence/display/AIRFLOW/Airflow+Improvements+Proposals)) is needed.
   In case of a new dependency, check compliance with the [ASF 3rd Party License Policy](https://www.apache.org/legal/resolved.html#category-x).
   In case of backwards incompatible changes please leave a note in [UPDATING.md](https://github.com/apache/airflow/blob/master/UPDATING.md).
   


----------------------------------------------------------------
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

For queries about this service, please contact Infrastructure at:
users@infra.apache.org



[GitHub] [airflow] XD-DENG commented on a change in pull request #13449: Streamline & simplify __eq__ methods in models Dag and BaseOperator

Posted by GitBox <gi...@apache.org>.
XD-DENG commented on a change in pull request #13449:
URL: https://github.com/apache/airflow/pull/13449#discussion_r551008494



##########
File path: airflow/models/dag.py
##########
@@ -361,8 +361,7 @@ def __repr__(self):
         return f"<DAG: {self.dag_id}>"
 
     def __eq__(self, other):
-        if type(self) == type(other) and self.dag_id == other.dag_id:
-
+        if type(self) == type(other):

Review comment:
       That optimisation may not make sense given two reasons below:
   - `all()` function has the "exit fast" property, i.e., whenever there is any `False` element, it will return `False` immediately, rather than traversing all elements in the iterable. [reference](https://docs.python.org/3/library/functions.html#all)
   - For `dag` model, `dag_id` is the 1st element in `_comps`; For `BaseOperator`, `task_id` is the 1st element in `_comps`.
   
   So after the change I make here, there should be zero impact on the performance (actually it improves the performance very minorly: it helps avoid comparing `dag_id` in `dag` model's `__eq__`for two times. Similar for `BaseOperator`).
   
   Kindly let me know if it makes sense to you?




----------------------------------------------------------------
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

For queries about this service, please contact Infrastructure at:
users@infra.apache.org



[GitHub] [airflow] github-actions[bot] commented on pull request #13449: Streamline & simplify __eq__ methods in models Dag and BaseOperator

Posted by GitBox <gi...@apache.org>.
github-actions[bot] commented on pull request #13449:
URL: https://github.com/apache/airflow/pull/13449#issuecomment-753609508


   [The Workflow run](https://github.com/apache/airflow/actions/runs/459150700) is cancelling this PR. It has some failed jobs matching ^Pylint$,^Static checks,^Build docs$,^Spell check docs$,^Backport packages$,^Provider packages,^Checks: Helm tests$,^Test OpenAPI*.


----------------------------------------------------------------
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

For queries about this service, please contact Infrastructure at:
users@infra.apache.org



[GitHub] [airflow] mik-laj merged pull request #13449: Streamline & simplify __eq__ methods in models Dag and BaseOperator

Posted by GitBox <gi...@apache.org>.
mik-laj merged pull request #13449:
URL: https://github.com/apache/airflow/pull/13449


   


----------------------------------------------------------------
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

For queries about this service, please contact Infrastructure at:
users@infra.apache.org



[GitHub] [airflow] github-actions[bot] commented on pull request #13449: Streamline & simplify __eq__ methods in models Dag and BaseOperator

Posted by GitBox <gi...@apache.org>.
github-actions[bot] commented on pull request #13449:
URL: https://github.com/apache/airflow/pull/13449#issuecomment-753734333


   The PR most likely needs to run full matrix of tests because it modifies parts of the core of Airflow. However, committers might decide to merge it quickly and take the risk. If they don't merge it quickly - please rebase it to the latest master at your convenience, or amend the last commit of the PR, and push it with --force-with-lease.


----------------------------------------------------------------
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

For queries about this service, please contact Infrastructure at:
users@infra.apache.org



[GitHub] [airflow] mik-laj commented on a change in pull request #13449: Streamline & simplify __eq__ methods in models Dag and BaseOperator

Posted by GitBox <gi...@apache.org>.
mik-laj commented on a change in pull request #13449:
URL: https://github.com/apache/airflow/pull/13449#discussion_r551099431



##########
File path: airflow/models/dag.py
##########
@@ -361,8 +361,7 @@ def __repr__(self):
         return f"<DAG: {self.dag_id}>"
 
     def __eq__(self, other):
-        if type(self) == type(other) and self.dag_id == other.dag_id:
-
+        if type(self) == type(other):

Review comment:
       SGTM. 




----------------------------------------------------------------
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

For queries about this service, please contact Infrastructure at:
users@infra.apache.org



[GitHub] [airflow] mik-laj commented on a change in pull request #13449: Streamline & simplify __eq__ methods in models Dag and BaseOperator

Posted by GitBox <gi...@apache.org>.
mik-laj commented on a change in pull request #13449:
URL: https://github.com/apache/airflow/pull/13449#discussion_r551007275



##########
File path: airflow/models/dag.py
##########
@@ -361,8 +361,7 @@ def __repr__(self):
         return f"<DAG: {self.dag_id}>"
 
     def __eq__(self, other):
-        if type(self) == type(other) and self.dag_id == other.dag_id:
-
+        if type(self) == type(other):

Review comment:
       See: https://github.com/apache/airflow/commit/36e76fa08912a5f35eee940873814e6204f0873c and https://github.com/apache/airflow/pull/4322/files#r241802863




----------------------------------------------------------------
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

For queries about this service, please contact Infrastructure at:
users@infra.apache.org



[GitHub] [airflow] mik-laj commented on a change in pull request #13449: Streamline & simplify __eq__ methods in models Dag and BaseOperator

Posted by GitBox <gi...@apache.org>.
mik-laj commented on a change in pull request #13449:
URL: https://github.com/apache/airflow/pull/13449#discussion_r551006565



##########
File path: airflow/models/dag.py
##########
@@ -361,8 +361,7 @@ def __repr__(self):
         return f"<DAG: {self.dag_id}>"
 
     def __eq__(self, other):
-        if type(self) == type(other) and self.dag_id == other.dag_id:
-
+        if type(self) == type(other):

Review comment:
       From what I can remember, it's optimization so we can check the most common case much faster.




----------------------------------------------------------------
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

For queries about this service, please contact Infrastructure at:
users@infra.apache.org



[GitHub] [airflow] mik-laj commented on a change in pull request #13449: Streamline & simplify __eq__ methods in models Dag and BaseOperator

Posted by GitBox <gi...@apache.org>.
mik-laj commented on a change in pull request #13449:
URL: https://github.com/apache/airflow/pull/13449#discussion_r551007275



##########
File path: airflow/models/dag.py
##########
@@ -361,8 +361,7 @@ def __repr__(self):
         return f"<DAG: {self.dag_id}>"
 
     def __eq__(self, other):
-        if type(self) == type(other) and self.dag_id == other.dag_id:
-
+        if type(self) == type(other):

Review comment:
       See: https://github.com/apache/airflow/commit/36e76fa08912a5f35eee940873814e6204f0873c




----------------------------------------------------------------
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

For queries about this service, please contact Infrastructure at:
users@infra.apache.org