turbaszek commented on a change in pull request #8805:
URL: https://github.com/apache/airflow/pull/8805#discussion_r422638768



##########
File path: airflow/models/baseoperator.py
##########
@@ -60,9 +60,25 @@
 ScheduleInterval = Union[str, timedelta, relativedelta]
 
 
+class BaseOperatorMeta(type):
+    """
+    Base metaclass of BaseOperator.
+    """
+    def __call__(cls, *args, **kwargs):
+        """
+        Called when you call BaseOperator(). In this way we are able to 
perform an action
+        after initializing an operator no matter where  the 
``super().__init__`` is called
+        (before or after assign of new attributes in a custom operator).
+        """
+        obj = type.__call__(cls, *args, **kwargs)
+        # Set upstream task defined by XComArgs passed to template fields of 
an operator
+        obj._set_xcomargs_dependencies()  # pylint: disable=protected-access

Review comment:
       > meta_class introduce backward compatibility problems for users who 
already have metaclass defined for their operator ( they will have to inherit 
from BaseOperatorMeta)
   
   True
   
   > what happens when a user creates an operator without DAG?
   
   Well, nothing. If the question is about 
https://github.com/apache/airflow/pull/8805#discussion_r422633456 then 
AirflowException on missing DAG is raised. I've added a test for that.
   
   > 1. we can fix set_upstream
   
   Is this related to this comment 
https://github.com/apache/airflow/pull/8805#discussion_r422633321 ?
   
   > 2. we can just finalize Operator implementation when we add it to dag ( 
thus no metaclass is required)
   
   User can either provide the `dag` argument to operator or if it's `None` 
then we call `DagContext.get_current_dag()` . Both happens during `__init__` 
call, so I'm not sure if I understand when the "add to dag" moment happens.
   
   




----------------------------------------------------------------
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:
[email protected]


Reply via email to