kaxil commented on code in PR #74421:
URL: https://github.com/apache/airflow/pull/74421#discussion_r4551157127
##########
task-sdk/tests/task_sdk/execution_time/test_context.py:
##########
@@ -1962,6 +1963,87 @@ def
test_get_with_custom_backend_removes_decoration_marker(self, mock_supervisor
assert result == {"rows": 123}
backend.deserialize_task_state_store_from_ref.assert_called_once_with("s3://bucket/ti_123/job_id")
+ def test_set_with_custom_backend_returning_none_stores_value_inline(self,
mock_supervisor_comms):
+ """A backend that returns None keeps the value inline, with no marker
around it."""
+ mock_supervisor_comms.send.return_value = OKResponse(ok=True)
+
+ backend = MagicMock(spec=BaseStoreBackend)
+ backend.serialize_task_state_store_to_ref.return_value = None
+
+ with (
+
patch("airflow.sdk.execution_time.context._get_worker_state_store_backend",
return_value=backend),
+ conf_vars({("state_store", "default_retention_days"): "0"}),
+ ):
+ TaskStateStoreAccessor(ti_id=self.TI_ID,
scope=self.SCOPE).set("progress", {"count": 5})
+
+ mock_supervisor_comms.send.assert_called_once_with(
+ SetTaskStateStore(ti_id=self.TI_ID, key="progress",
value={"count": 5}, expires_at=None)
+ )
+
+ def
test_get_with_custom_backend_returns_unmarked_value_without_deserializing(
+ self, mock_supervisor_comms
+ ):
+ """A value stored inline (or written through the REST API) is returned
as-is."""
+ mock_supervisor_comms.send.return_value =
TaskStateStoreResult(value={"count": 5})
+
+ backend = MagicMock(spec=BaseStoreBackend)
+
+ with (
+
patch("airflow.sdk.execution_time.context._get_worker_state_store_backend",
return_value=backend),
+ patch("airflow.sdk.execution_time.context.log",
spec=structlog.stdlib.BoundLogger) as mock_log,
+ ):
+ result = TaskStateStoreAccessor(ti_id=self.TI_ID,
scope=self.SCOPE).get("progress")
+
+ assert result == {"count": 5}
+ backend.deserialize_task_state_store_from_ref.assert_not_called()
+ mock_log.warning.assert_not_called()
+
+ @pytest.mark.parametrize(
+ "stored",
+ [
+ pytest.param({"__airflow_state_ref__": "/tmp/x", "other": 1},
id="marker-with-other-keys"),
+ pytest.param({"__airflow_state_ref__": 1},
id="non-string-marker-value"),
+ ],
+ )
+ def
test_get_with_custom_backend_returns_marker_lookalike_without_deserializing(
+ self, mock_supervisor_comms, stored
+ ):
+ """Only an exact ``{marker: str}`` wrapper is treated as a backend
reference."""
+ mock_supervisor_comms.send.return_value =
TaskStateStoreResult(value=stored)
+
+ backend = MagicMock(spec=BaseStoreBackend)
+
+ with patch(
+
"airflow.sdk.execution_time.context._get_worker_state_store_backend",
return_value=backend
+ ):
+ result = TaskStateStoreAccessor(ti_id=self.TI_ID,
scope=self.SCOPE).get("job_id")
+
+ assert result == stored
+ backend.deserialize_task_state_store_from_ref.assert_not_called()
+
+ def test_get_with_custom_backend_resolves_empty_string_ref(self,
mock_supervisor_comms):
+ """An empty reference is still a reference: set() wraps it, so get()
must resolve it."""
+ mock_supervisor_comms.send.return_value =
TaskStateStoreResult(value=_wrap_external_ref(""))
+
+ backend = MagicMock(spec=BaseStoreBackend)
+ backend.deserialize_task_state_store_from_ref.return_value = "resolved"
+
+ with patch(
+
"airflow.sdk.execution_time.context._get_worker_state_store_backend",
return_value=backend
+ ):
+ result = TaskStateStoreAccessor(ti_id=self.TI_ID,
scope=self.SCOPE).get("job_id")
+
+ assert result == "resolved"
+
backend.deserialize_task_state_store_from_ref.assert_called_once_with("")
+
+ def test_set_rejects_value_with_reserved_marker_key(self,
mock_supervisor_comms):
Review Comment:
Parametrized with both shapes, for the task and asset accessors.
##########
shared/state/src/airflow_shared/state/__init__.py:
##########
Review Comment:
Added `74421.significant.rst`.
--
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]