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 2022/10/16 22:07:24 UTC

[GitHub] [airflow] alexandermalyga opened a new issue, #27081: Wrong missing args error when initialising operator with multiple inheritance

alexandermalyga opened a new issue, #27081:
URL: https://github.com/apache/airflow/issues/27081

   ### Apache Airflow version
   
   2.4.1
   
   ### What happened
   
   When initialising an operator with multiple inheritance, an exception is raised: 
   `airflow.exceptions.AirflowException: missing keyword argument ...`
   
   This only happens when multiple parent classes share an attribute name in their `__init__` method.
   
   ### What you think should happen instead
   
   Multiple inheritance with shared attribute names in the parent classes should work as expected in Python.
   
   ### How to reproduce
   
   Run this python script:
   
   ```
   from airflow.models import BaseOperator
   
   class A(BaseOperator):
       def __init__(self, *, value: str, **kwargs):
           super().__init__(**kwargs)
   
   class B(BaseOperator):
       def __init__(self, *, value: str, **kwargs):
           super().__init__(**kwargs)
   
   class C(A, B):
       def __init__(self, *, value: str, **kwargs):
           super().__init__(value=value, **kwargs)
   
   C(task_id="test", value="value")
   ```
   
   ### Operating System
   
   macOS 12.6
   
   ### Versions of Apache Airflow Providers
   
   _No response_
   
   ### Deployment
   
   Docker-Compose
   
   ### Deployment details
   
   _No response_
   
   ### Anything else
   
   The issue seems to be somehow caused by the @apply_defaults decorator and signature caching, but I'm not very familiar with it.
   
   Related: 
   
   - https://stackoverflow.com/questions/54529660/airflow-apply-defaults-decorator-reports-argument-is-required
   - https://lists.apache.org/thread/kwfdk17t8gfrv6fbwoc041sr8thgt4p3
   
   
   ### Are you willing to submit PR?
   
   - [X] Yes I am willing to submit a PR!
   
   ### Code of Conduct
   
   - [X] I agree to follow this project's [Code of Conduct](https://github.com/apache/airflow/blob/main/CODE_OF_CONDUCT.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.

To unsubscribe, e-mail: commits-unsubscribe@airflow.apache.org.apache.org

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


[GitHub] [airflow] uranusjr commented on issue #27081: Wrong missing args error when initialising operator with multiple inheritance

Posted by GitBox <gi...@apache.org>.
uranusjr commented on issue #27081:
URL: https://github.com/apache/airflow/issues/27081#issuecomment-1280243692

   > work as expected in Python.
   
   How? I removed `BaseOperator` from the given example:
   
   ```python
   class R:
       def __init__(**kwargs):
           pass
   
   class A(R):
       def __init__(self, *, value: str, **kwargs):
           super().__init__(**kwargs)
   
   class B(R):
       def __init__(self, *, value: str, **kwargs):
           super().__init__(**kwargs)
   
   class C(A, B):
       def __init__(self, *, value: str, **kwargs):
           super().__init__(value=value, **kwargs)
   
   C(task_id="test", value="value")
   ```
   
   And it still fails.
   
   ```
   Traceback (most recent call last):
     File "<stdin>", line 24, in <module>
       C(task_id="test", value="value")
     File "<stdin>", line 21, in __init__
       super().__init__(value=value, **kwargs)
     File "<stdin>", line 11, in __init__
       super().__init__(**kwargs)
   TypeError: __init__() missing 1 required keyword-only argument: 'value'
   ```
   
   Python’s `super` chain follows MRO (C→B→A→BaseOperator in this example), so the `super().__init__` calls in `C.__init__` calls `B.__init__`, **and the `super().__init__` in `B.__init__` calls `A.__init__`**, which is missing the required `value` argument.
   
   From what I can tell, `apply_defaults` is doing its job properly. It obscures the traceback, which we could improve, but the error is legistimate.


-- 
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.

To unsubscribe, e-mail: commits-unsubscribe@airflow.apache.org

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


[GitHub] [airflow] uranusjr closed issue #27081: Wrong missing args error when initialising operator with multiple inheritance

Posted by GitBox <gi...@apache.org>.
uranusjr closed issue #27081: Wrong missing args error when initialising operator with multiple inheritance
URL: https://github.com/apache/airflow/issues/27081


-- 
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.

To unsubscribe, e-mail: commits-unsubscribe@airflow.apache.org

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