amoghrajesh commented on code in PR #67319:
URL: https://github.com/apache/airflow/pull/67319#discussion_r3322236083


##########
airflow-core/src/airflow/api_fastapi/core_api/datamodels/task_state.py:
##########
@@ -40,6 +44,34 @@ class TaskStateCollectionResponse(BaseModel):
 
 
 class TaskStateBody(StrictBaseModel):
-    """Request body for setting a task state value."""
+    """
+    Request body for setting a task state value.
+
+    ``expires_at`` controls expiry:
+
+    - ``"default"``: apply the configured ``[state_store] 
default_retention_days``.
+    - ``null``: never expire.
+    - aware datetime: expire at that time.
+    """
 
     value: str = Field(max_length=65535)
+    expires_at: AwareDatetime | None | Literal["default"] = "default"
+
+
+class TaskStatePatchBody(StrictBaseModel):
+    """Request body for patching only the value of an existing task state 
key."""
+
+    value: JsonValue
+
+    @field_validator("value")
+    @classmethod
+    def value_is_json_representable(cls, v: JsonValue) -> JsonValue:
+        if v is None:
+            raise ValueError("value cannot be null")
+        try:
+            serialized = json.dumps(v, allow_nan=False)
+        except ValueError:
+            raise ValueError("value contains non-finite numbers; NaN and Inf 
are not JSON representable")

Review Comment:
   `value` is typed as `JsonValue` (`str | int | float | bool | None | 
list[JsonValue] | dict[str, JsonValue]`), so the only values that can cause 
`json.dumps(v, allow_nan=False)` to raise are IEEE 754 non finite floats such 
as nan, inf, -inf. 
   
   `TypeError` can't happen here because all branches of `JsonValue` are 
natively serializable. Also, the standard REST clients cannot even send NaN (it 
is not a valid json), the only way to reach this path is a client which sends 
some data with encoding as `allow_nan=True`. So the message is precise for this 
field type, not misleading. Keeping it that way



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