pankajastro commented on code in PR #74421:
URL: https://github.com/apache/airflow/pull/74421#discussion_r4283317288


##########
task-sdk/src/airflow/sdk/execution_time/context.py:
##########
@@ -809,14 +803,15 @@ def _build_set_message(
                 )
             expires_at = None if days == 0 else now + timedelta(days=days)
 
-        # if custom backend is configured, store the value on the custom 
backend, and return the reference
-        # to the stored value to store in the DB
+        # if a custom backend is configured, it may store the value externally 
and return a reference to keep
+        # in the DB, or return None to keep the value inline
         backend = _get_worker_state_store_backend()
         stored: JsonValue = value
         if backend is not None:
-            ref: str = backend.serialize_task_state_store_to_ref(value=value, 
key=key, scope=self._scope)
-            # wrap the value with a marker to indicate that it's stored 
externally, and include the ref to the external storage
-            stored = _wrap_external_ref(ref)
+            ref = backend.serialize_task_state_store_to_ref(value=value, 
key=key, scope=self._scope)
+            if ref is not None:

Review Comment:
   `set()` wraps on `ref is not None` while `get()` unwraps on truthiness. If a 
backend returns `""`, wouldn't `get()` hand back the raw wrapper dict? Should 
`get()` also check `ref is not None`? (The asset `set` at line 967 has the same 
shape.)
   
   ---
   Drafted-by: Claude Code (Sonnet 5.5); reviewed by @pankajastro before posting



##########
task-sdk/src/airflow/sdk/execution_time/context.py:
##########
@@ -756,13 +756,7 @@ def _extract_get_response(self, resp: Any, key: str, 
default: JsonValue) -> Json
             if backend is not None and isinstance(stored, dict) and (ref := 
_unwrap_external_ref(stored)):

Review Comment:
   If a backend returns `None` and a user value like `{"__airflow_state_ref__": 
"/tmp/x"}` is stored raw, wouldn't `get()` pass `"/tmp/x"` to 
`deserialize_*_from_ref`? Could `_unwrap_external_ref` require the marker to be 
the only key with a `str` value, and could a test cover that case? (The asset 
`get` at line 938 has the same guard.)
   
   ---
   Drafted-by: Claude Code (Sonnet 5.5); reviewed by @pankajastro before posting



##########
airflow-core/docs/administration-and-deployment/task-and-asset-state-store.rst:
##########
@@ -214,18 +221,28 @@ Example skeleton:
             safe = hashlib.sha256(asset_identifier.encode()).hexdigest()[:16]
             return f"airflow/asset-store/{safe}/{key}"
 
-        def serialize_task_state_store_to_ref(self, *, value: JsonValue, key: 
str, scope: TaskScope) -> str:
+        def serialize_task_state_store_to_ref(
+            self, *, value: JsonValue, key: str, scope: TaskScope
+        ) -> str | None:
+            payload = json.dumps(value).encode()
+            if len(payload) < THRESHOLD_BYTES:
+                return None  # small enough to keep in the database

Review Comment:
   The paragraph above tells backends that also run on older Airflow to return 
`super()...` for inline values, but this skeleton returns `None` directly. 
Should the skeleton use `super()`, or carry a note that it needs an SDK that 
supports inline values?
   
   ---
   Drafted-by: Claude Code (Sonnet 5.5); reviewed by @pankajastro before posting



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