You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@airflow.apache.org by "eladkal (via GitHub)" <gi...@apache.org> on 2023/03/01 07:05:01 UTC

[GitHub] [airflow] eladkal commented on a diff in pull request #29821: Add a check for not templateable fields

eladkal commented on code in PR #29821:
URL: https://github.com/apache/airflow/pull/29821#discussion_r1121242914


##########
airflow/serialization/serialized_objects.py:
##########
@@ -770,8 +772,12 @@ def _serialize_node(cls, op: BaseOperator | MappedOperator, include_deps: bool)
 
         # Store all template_fields as they are if there are JSON Serializable
         # If not, store them as strings
+        # And raise an exception if the field is not templateable
+        forbidden_fields = set(inspect.signature(BaseOperator.__init__).parameters.keys())
         if op.template_fields:
             for template_field in op.template_fields:
+                if template_field in forbidden_fields:
+                    raise AirflowException(f"Cannot use {template_field} as template field")

Review Comment:
   I think the only use case where we can not template fields is when user wants to template BaseOperator parameters which is something that can't be done. So maybe we can be more informative on the exception here? 



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