Similar to #45043, we need a similar thing for Task SDK to fetch Variable from Task Context.
Requirement:
- A minimal
Variable user-facing object in Task SDK definition for use in the DAG file - Logic to get
Variable in the context.
| "var": { |
| "json": VariableAccessor(deserialize_json=True), |
| "value": VariableAccessor(deserialize_json=False), |
| }, |
| classVariableAccessor: |
| """Wrapper to access Variable values in template.""" |
| |
| def__init__(self, *, deserialize_json: bool) ->None: |
| self._deserialize_json=deserialize_json |
| self.var: Any=None |
| |
| def__getattr__(self, key: str) ->Any: |
| fromairflow.models.variableimportVariable |
| |
| self.var=Variable.get(key, deserialize_json=self._deserialize_json) |
| returnself.var |
| |
| def__repr__(self) ->str: |
| returnstr(self.var) |
| |
| defget(self, key, default: Any=NOTSET) ->Any: |
| fromairflow.models.variableimportVariable |
| |
| ifdefaultisNOTSET: |
| returnVariable.get(key, deserialize_json=self._deserialize_json) |
| returnVariable.get(key, default, deserialize_json=self._deserialize_json) |
Now, we will need following 3 related objects:
VariableResponse is auto-generated and tightly coupled with the API schema.VariableResult is runtime-specific and meant for internal communication between Supervisor & Task Runner.Variable class here is where the public-facing, user-relevant aspects are exposed, hiding internal details.
Similar to #45043, we need a similar thing for Task SDK to fetch Variable from Task Context.
Requirement:
Variableuser-facing object in Task SDK definition for use in the DAG fileVariablein the context.airflow/airflow/models/taskinstance.py
Lines 1043 to 1046 in f03b1d4
airflow/airflow/utils/context.py
Lines 117 to 138 in f03b1d4
Now, we will need following 3 related objects:
VariableResponseis auto-generated and tightly coupled with the API schema.VariableResultis runtime-specific and meant for internal communication between Supervisor & Task Runner.Variableclass here is where the public-facing, user-relevant aspects are exposed, hiding internal details.