hussein-awala commented on code in PR #77198:
URL: https://github.com/apache/airflow/pull/77198#discussion_r4641410633
##########
providers/common/ai/src/airflow/providers/common/ai/plugins/hitl_review.py:
##########
@@ -135,20 +140,20 @@ def _read_xcom_by_prefix(
include_node_regions=False,
)
entity = read.column_descriptions[0]["entity"]
- query = read.with_only_columns(entity.key,
entity.value).where(entity.key.like(f"{prefix}%"))
+ query = read.where(entity.key.like(f"{prefix}%"))
else:
- query = select(XComModel.key, XComModel.value).where(
+ query = select(XComModel).where(
XComModel.dag_id == dag_id,
XComModel.run_id == run_id,
XComModel.task_id == task_id,
XComModel.map_index == map_index,
XComModel.key.like(f"{prefix}%"),
)
result: dict[int, Any] = {}
- for key, value in session.execute(query).all():
- suffix = key[len(prefix) :]
+ for row in session.scalars(query):
+ suffix = row.key[len(prefix) :]
if suffix.isdigit():
- result[int(suffix)] = value
+ result[int(suffix)] = _load_xcom_value(row)
Review Comment:
Good catch, and it went beyond the plugin's own write: below
`xcom_objectstorage_threshold` the worker also stores Required Actions feedback
and model outputs as bare strings, so a typed or generated path came back the
same way. 87f4933 has the worker and the plugin store outputs and feedback as
`{"text": ..., "dag_id": ...}`, and the plugin shows only the text of such a
value for this Dag; any other value is shown as stored, never what it points
to. `TestReviewTextHoldingAStoragePath` reproduces it with the real
`XComObjectStorageBackend` on a `file://` base path, and the docs line now says
this.
##########
providers/common/ai/tests/unit/common/ai/plugins/test_hitl_review.py:
##########
@@ -1736,6 +1737,126 @@ def test_reject_returns_session(self, test_client):
assert response.json()["status"] == "rejected"
+class _ReferenceXComBackend(BaseXCom):
+ """Keep values outside the metadata database and store a reference there,
as object-storage backends do."""
+
+ stored: dict[str, Any] = {}
+
+ @staticmethod
+ def deserialize_value(result) -> Any:
+ value = BaseXCom.deserialize_value(result)
+ if isinstance(value, str):
+ return _ReferenceXComBackend.stored.get(value, value)
+ return value
+
+
+class _LoadValueReferenceXComBackend(BaseXCom):
+ """Resolve the same references through ``load_value`` only, as
``store_value`` backends do."""
+
+ @classmethod
+ def load_value(cls, stored) -> Any:
+ value = super().load_value(stored)
+ if isinstance(value, str):
+ return _ReferenceXComBackend.stored.get(value, value)
+ return value
+
+
+class TestReferenceStoringXComBackend:
+ """Review XComs a custom backend stored as references are read through the
backend."""
+
+ PARAMS = {"dag_id": TEST_DAG_ID, "run_id": TEST_RUN_ID, "task_id":
TEST_TASK_ID}
+
+ @pytest.fixture(
+ autouse=True,
+ params=[
+ pytest.param(_ReferenceXComBackend, id="deserialize_value"),
+ pytest.param(
+ _LoadValueReferenceXComBackend,
+ id="load_value",
+ marks=pytest.mark.skipif(
+ not hasattr(BaseXCom, "load_value"), reason="This Airflow
version has no load_value hook"
+ ),
+ ),
+ ],
+ )
+ def setup(self, request, monkeypatch, dag_maker, session):
+
monkeypatch.setattr("airflow.providers.common.ai.plugins.hitl_review.XCom",
request.param)
Review Comment:
Right, thanks. The setattr now passes `raising=False`, and against main's
plugin the eight reference-backend tests now fail with the `AgentSessionData`
validation error instead of erroring in setup.
--
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]