Taragolis commented on code in PR #34890:
URL: https://github.com/apache/airflow/pull/34890#discussion_r1357500864
##########
airflow/providers/amazon/aws/operators/lambda_function.py:
##########
@@ -62,13 +61,15 @@ class LambdaCreateFunctionOperator(BaseOperator):
:param aws_conn_id: The AWS connection ID to use
"""
+ aws_hook_class = LambdaHook
template_fields: Sequence[str] = (
"function_name",
"runtime",
"role",
"handler",
"code",
"config",
+ *AwsBaseOperator.template_fields,
Review Comment:
I think we could update it only in init method, at least I don't know
another way to change class attribute during creation, and I'm not sure is it
works on each cases or not (especially for mapped tasks).
Another way it is make parameters as set, but this have side effect, set
doesn't preserve the order, and it might generate new serialised DAG each time
it parsed (maybe it is not so bad)
```python
class Base:
templates_fields: set[str] = {"a", "b", "c"}
class Child1(Base):
...
class Child2(Base):
templates_fields = Base.templates_fields | {"d", "e"}
class Child3(Base):
...
print(" Step 1 ".center(72, "="))
print(f"Base.templates_fields={Base.templates_fields}")
print(f"Child1.templates_fields={Child1.templates_fields}")
print(f"Child2.templates_fields={Child2.templates_fields} - the order would
change from run to run")
print(f"Child3.templates_fields={Child3.templates_fields}")
print(" Step 2: Update one of the child ".center(72, "="))
Child3.templates_fields.update({"f", "g"})
print(f"Base.templates_fields={Base.templates_fields}")
print(f"Child1.templates_fields={Child1.templates_fields}")
print(f"Child2.templates_fields={Child2.templates_fields} - the order would
change from run to run")
print(f"Child3.templates_fields={Child3.templates_fields}")
print(" Step 3: Invalid operation ".center(72, "="))
class Child5(Base):
templates_fields.add("h") # We can't do that
```
```console
================================ Step 1 ================================
Base.templates_fields={'b', 'c', 'a'}
Child1.templates_fields={'b', 'c', 'a'}
Child2.templates_fields={'e', 'b', 'd', 'c', 'a'} - the order would change
from run to run
Child3.templates_fields={'b', 'c', 'a'}
=================== Step 2: Update one of the child ====================
Base.templates_fields={'b', 'f', 'g', 'c', 'a'}
Child1.templates_fields={'b', 'f', 'g', 'c', 'a'}
Child2.templates_fields={'e', 'b', 'd', 'c', 'a'} - the order would change
from run to run
Child3.templates_fields={'b', 'f', 'g', 'c', 'a'}
====================== Step 3: Invalid operation =======================
Traceback (most recent call last):
...
NameError: name 'templates_fields' is not defined
```
--
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]