You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@airflow.apache.org by ka...@apache.org on 2021/01/04 03:12:43 UTC

[airflow] branch master updated: Streamline & simplify __eq__ methods in models Dag and BaseOperator (#13449)

This is an automated email from the ASF dual-hosted git repository.

kamilbregula pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/airflow.git


The following commit(s) were added to refs/heads/master by this push:
     new 6ef23af  Streamline & simplify __eq__ methods in models Dag and BaseOperator (#13449)
6ef23af is described below

commit 6ef23aff802032e85ec42dabda83907bfd812b2c
Author: Xiaodong DENG <xd...@gmail.com>
AuthorDate: Mon Jan 4 04:12:31 2021 +0100

    Streamline & simplify __eq__ methods in models Dag and BaseOperator (#13449)
    
    - Use getattr() instead of __dict__ as __dict__ doesn't return
      correct values for properties.
    - Avoid unnecessary condition checks (the removed condition checks are covered by _comps)
---
 airflow/models/baseoperator.py | 6 ++++--
 airflow/models/dag.py          | 3 +--
 2 files changed, 5 insertions(+), 4 deletions(-)

diff --git a/airflow/models/baseoperator.py b/airflow/models/baseoperator.py
index 2e4e785..64ed4c5 100644
--- a/airflow/models/baseoperator.py
+++ b/airflow/models/baseoperator.py
@@ -520,8 +520,10 @@ class BaseOperator(Operator, LoggingMixin, TaskMixin, metaclass=BaseOperatorMeta
             )
 
     def __eq__(self, other):
-        if type(self) is type(other) and self.task_id == other.task_id:
-            return all(self.__dict__.get(c, None) == other.__dict__.get(c, None) for c in self._comps)
+        if type(self) is type(other):
+            # Use getattr() instead of __dict__ as __dict__ doesn't return
+            # correct values for properties.
+            return all(getattr(self, c, None) == getattr(other, c, None) for c in self._comps)
         return False
 
     def __ne__(self, other):
diff --git a/airflow/models/dag.py b/airflow/models/dag.py
index 1b639d5..3a7b5ec 100644
--- a/airflow/models/dag.py
+++ b/airflow/models/dag.py
@@ -361,8 +361,7 @@ class DAG(LoggingMixin):
         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):
             # Use getattr() instead of __dict__ as __dict__ doesn't return
             # correct values for properties.
             return all(getattr(self, c, None) == getattr(other, c, None) for c in self._comps)