Lee-W commented on code in PR #41325:
URL: https://github.com/apache/airflow/pull/41325#discussion_r1827587407


##########
airflow/decorators/assets.py:
##########
@@ -0,0 +1,159 @@
+# Licensed to the Apache Software Foundation (ASF) under one
+# or more contributor license agreements.  See the NOTICE file
+# distributed with this work for additional information
+# regarding copyright ownership.  The ASF licenses this file
+# to you under the Apache License, Version 2.0 (the
+# "License"); you may not use this file except in compliance
+# with the License.  You may obtain a copy of the License at
+#
+#   http://www.apache.org/licenses/LICENSE-2.0
+#
+# Unless required by applicable law or agreed to in writing,
+# software distributed under the License is distributed on an
+# "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+# KIND, either express or implied.  See the License for the
+# specific language governing permissions and limitations
+# under the License.
+
+from __future__ import annotations
+
+import inspect
+import types
+from collections.abc import Callable
+from functools import wraps
+from typing import TYPE_CHECKING, Any, Iterator, Mapping, cast
+
+import attrs
+
+from airflow.assets import Asset, AssetRef, _validate_identifier
+from airflow.models.asset import _fetch_active_assets_by_name
+from airflow.models.dag import DAG, ScheduleArg
+from airflow.providers.standard.operators.python import PythonOperator
+
+if TYPE_CHECKING:
+    from typing import Sequence
+
+    from airflow.io.path import ObjectStoragePath
+
+
+class _AssetMainOperator(PythonOperator):
+    def __init__(self, *, definition_name: str, uri: str | None = None, 
**kwargs) -> None:
+        super().__init__(**kwargs)
+        self._definition_name = definition_name
+        self._uri = uri
+        self._active_assets: dict[str, Asset] = {}
+
+    def _iter_kwargs(self, context: Mapping[str, Any]) -> Iterator[tuple[str, 
Any]]:
+        value: Any
+        for key in inspect.signature(self.python_callable).parameters:
+            if key == "self":
+                key = "_self"

Review Comment:
   ```python
   from __future__ import annotations
   
   import pendulum
   
   from airflow.assets import Asset
   from airflow.decorators import dag, task
   from airflow.decorators.assets import asset
   
   @asset(uri="s3://bucket/asset1_producer", schedule=None)
   def asset1_producer():
       pass
   
   @asset(uri="s3://bucket/object", schedule=None)
   def asset2_producer(self, context, asset1_producer):
       print(self)
       print(context["inlet_events"][asset1_producer][-1])
   
   @dag(
       schedule=Asset(uri="s3://bucket/asset1_producer", name="asset1_producer")
       | Asset(uri="s3://bucket/object", name="asset2_producer"),
       start_date=pendulum.datetime(2021, 1, 1, tz="UTC"),
       catchup=False,
       tags=["consumes", "asset-scheduled"],
   )
   def consumes_asset_decorator():
       @task(outlets=[Asset(uri="s3://consuming_1_task/asset_other.txt", 
name="endpoint")])
       def process_nothing():
           pass
   
       process_nothing()
   
   consumes_asset_decorator()
   ```
   
   When I remove this `_self` line and comment out the `_handle_self_argument` 
function, I encounter the following error
   
   ```
   Traceback (most recent call last):
     File "/opt/airflow/airflow/models/taskinstance.py", line 759, in 
_execute_task
       result = _execute_callable(context=context, **execute_callable_kwargs)
     File "/opt/airflow/airflow/models/taskinstance.py", line 725, in 
_execute_callable
       return ExecutionCallableRunner(
     File "/opt/airflow/airflow/utils/operator_helpers.py", line 258, in run
       return self.func(*args, **kwargs)
     File "/opt/airflow/airflow/models/baseoperator.py", line 375, in wrapper
       return func(self, *args, **kwargs)
     File 
"/opt/airflow/providers/src/airflow/providers/standard/operators/python.py", 
line 192, in execute
       return_value = self.execute_callable()
     File 
"/opt/airflow/providers/src/airflow/providers/standard/operators/python.py", 
line 210, in execute_callable
       return runner.run(*self.op_args, **self.op_kwargs)
   TypeError: run() got multiple values for argument 'self'
   ```



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

For queries about this service, please contact Infrastructure at:
[email protected]

Reply via email to