jason810496 commented on code in PR #48177:
URL: https://github.com/apache/airflow/pull/48177#discussion_r2011516571


##########
task-sdk/src/airflow/sdk/execution_time/context.py:
##########
@@ -193,6 +193,24 @@ def _get_variable(key: str, deserialize_json: bool) -> 
Variable:
     return _convert_variable_result_to_variable(msg, deserialize_json)
 
 
+def _set_variable(key: str, value: Any, description: str | None = None, 
serialize_json: bool = False) -> None:
+    from airflow.sdk.execution_time.comms import ErrorResponse, PutVariable
+    from airflow.sdk.execution_time.task_runner import SUPERVISOR_COMMS
+
+    if serialize_json:
+        import json
+
+        value = json.dumps(value, indent=2)
+    else:
+        value = str(value)
+
+    SUPERVISOR_COMMS.send_request(log=log, msg=PutVariable(key=key, 
value=value, description=description))
+    msg = SUPERVISOR_COMMS.get_message()
+    if isinstance(msg, ErrorResponse):
+        raise AirflowRuntimeError(msg)
+    return
+
+

Review Comment:
   I think I need to port the Secret Backend `check_for_write_conflict` logic 
from models ( 
https://github.com/apache/airflow/blob/main/airflow-core/src/airflow/models/variable.py#L198-L199
 ) to TaskSDK as well?  
   
   Just like `_get_variable`, right?  
   
https://github.com/apache/airflow/blob/main/task-sdk/src/airflow/sdk/execution_time/context.py#L154-L171
  
   
   cc @amoghrajesh



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