dandanseo123 commented on code in PR #64600:
URL: https://github.com/apache/airflow/pull/64600#discussion_r3029447577
##########
task-sdk/src/airflow/sdk/execution_time/task_runner.py:
##########
@@ -225,28 +235,33 @@ def get_template_context(self) -> Context:
# Cache the context object, which ensures that all calls to
get_template_context
# are operating on the same context object.
- self._cached_template_context: Context = self._cached_template_context
or {
- # From the Task Execution interface
- "dag": self.task.dag,
- "inlets": self.task.inlets,
- "map_index_template": self.task.map_index_template,
- "outlets": self.task.outlets,
- "run_id": self.run_id,
- "task": self.task,
- "task_instance": self,
- "ti": self,
- "outlet_events": OutletEventAccessors(),
- "inlet_events": InletEventsAccessors(self.task.inlets),
- "macros": MacrosAccessor(),
- "params": validated_params,
- # TODO: Make this go through Public API longer term.
- # "test_mode": task_instance.test_mode,
- "var": {
- "json": VariableAccessor(deserialize_json=True),
- "value": VariableAccessor(deserialize_json=False),
- },
- "conn": ConnectionAccessor(),
- }
+ if self._cached_template_context is None:
+ self._cached_template_context = {
+ # From the Task Execution interface
+ "dag": self.task.dag,
+ "inlets": self.task.inlets,
+ "map_index_template": self.task.map_index_template,
+ "outlets": self.task.outlets,
+ "run_id": self.run_id,
+ "task": self.task,
+ "task_instance": self,
+ "ti": self,
+ "outlet_events": OutletEventAccessors(),
+ "inlet_events": InletEventsAccessors(self.task.inlets),
+ "macros": MacrosAccessor(),
+ "params": validated_params,
+ # TODO: Make this go through Public API longer term.
+ # "test_mode": task_instance.test_mode,
+ "var": {
+ "json": VariableAccessor(deserialize_json=True),
+ "value": VariableAccessor(deserialize_json=False),
+ },
+ "conn": ConnectionAccessor(),
+ }
+
+ # After initialization, _cached_template_context is definitely not None
+ context = self._cached_template_context
+
Review Comment:
addressed.
--
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]