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


##########
providers/common/io/tests/unit/common/io/state_store/test_backend.py:
##########
@@ -368,15 +368,48 @@ def test_serialize_threshold_boundary_roundtrips(
             store = StateStoreObjectStorageBackend()
             scope = request.getfixturevalue(scope_fixture)
             ref = getattr(store, serialize)(value=value, key="k", scope=scope)
-            result = getattr(store, deserialize)(ref)
 
-            assert result == value
             if offloaded:
                 assert ref.startswith("file://")
                 assert len(ObjectStoragePath(ref).read_bytes()) == stored_size
+                assert getattr(store, deserialize)(ref) == value
             else:
-                assert len(ref) == stored_size
-                assert not ref.startswith("file://")
+                # The base class default keeps the value inline in the 
database.
+                assert ref is None

Review Comment:
   This fails the 3.3.2/3.4.0 compat runs, where the base default returns 
`json.dumps(value)`. How about comparing against the installed base?
   ```suggestion
                   # Below the threshold the backend defers to the installed 
SDK's default.
                   assert ref == getattr(BaseStoreBackend, serialize)(store, 
value=value, key="k", scope=scope)
   ```



##########
airflow-core/docs/administration-and-deployment/task-and-asset-state-store.rst:
##########
@@ -216,18 +223,30 @@ 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:
+                # Keep small values in the database; super() returns the right 
default for this Airflow version.
+                return super().serialize_task_state_store_to_ref(value=value, 
key=key, scope=scope)
             s3_key = self._task_ref(scope, key)
-            s3_client.put_object(Bucket=BUCKET, Key=s3_key, 
Body=json.dumps(value).encode())
+            s3_client.put_object(Bucket=BUCKET, Key=s3_key, Body=payload)
             return s3_key
 
         def deserialize_task_state_store_from_ref(self, stored: str) -> 
JsonValue:
             s3_object = s3_client.get_object(Bucket=BUCKET, Key=stored)
             return json.loads(s3_object["Body"].read().decode())

Review Comment:
   On older Airflow, `super()` stores inline JSON as the ref, so `get_object` 
fails here. Could we fall back to `json.loads`? Same for the asset variant.
   ```suggestion
           def deserialize_task_state_store_from_ref(self, stored: str) -> 
JsonValue:
               if not stored.startswith("airflow/"):
                   # Older Airflow versions keep small values as a JSON-string 
reference.
                   return json.loads(stored)
               s3_object = s3_client.get_object(Bucket=BUCKET, Key=stored)
               return json.loads(s3_object["Body"].read().decode())
   ```



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