jason810496 commented on code in PR #54903:
URL: https://github.com/apache/airflow/pull/54903#discussion_r2315973292
##########
airflow-core/tests/unit/api_fastapi/common/test_parameters.py:
##########
@@ -18,11 +18,72 @@
from __future__ import annotations
import re
+from typing import Annotated
import pytest
-from fastapi import HTTPException
+from fastapi import Depends, FastAPI, HTTPException
-from airflow.api_fastapi.common.parameters import SortParam
+from airflow.api_fastapi.common.parameters import FilterParam, SortParam,
filter_param_factory
+from airflow.models import DagRun, Log
+
+
+class TestFilterParam:
+ def test_filter_param_factory_description(self):
+ app = FastAPI() # Create a FastAPI app to test OpenAPI generation
+ expected_descriptions = {
+ "dag_id": "Filter by DAG ID Description",
+ "task_id": "Filter by Task ID Description",
+ "map_index": None, # No description for map_index
+ "run_id": "Filter by Run ID Description",
+ }
+
+ @app.get("/test")
+ def test_route(
+ dag_id: Annotated[
+ FilterParam[str | None],
+ Depends(
+ filter_param_factory(Log.dag_id, str | None,
description="Filter by DAG ID Description")
+ ),
+ ],
+ task_id: Annotated[
+ FilterParam[str | None],
+ Depends(
+ filter_param_factory(Log.task_id, str | None,
description="Filter by Task ID Description")
+ ),
+ ],
+ map_index: Annotated[
+ FilterParam[int | None],
+ Depends(filter_param_factory(Log.map_index, int | None)),
+ ],
Review Comment:
I have tried to use `pytest.mark.parameterize` to render the test cases, but
it result in some FastAPI internal error.
```
/usr/local/lib/python3.10/site-packages/fastapi/applications.py:981: in
openapi
self.openapi_schema = get_openapi(
/usr/local/lib/python3.10/site-packages/fastapi/openapi/utils.py:514: in
get_openapi
field_mapping, definitions = get_definitions(
/usr/local/lib/python3.10/site-packages/fastapi/_compat.py:232: in
get_definitions
field_mapping, definitions = schema_generator.generate_definitions(
/usr/local/lib/python3.10/site-packages/pydantic/json_schema.py:363: in
generate_definitions
self.generate_inner(schema)
/usr/local/lib/python3.10/site-packages/pydantic/json_schema.py:443: in
generate_inner
if 'ref' in schema:
/usr/local/lib/python3.10/_collections_abc.py:830: in __contains__
self[key]
/usr/local/lib/python3.10/site-packages/pydantic/_internal/_mock_val_ser.py:41:
in __getitem__
return self._get_built().__getitem__(key)
/usr/local/lib/python3.10/site-packages/pydantic/_internal/_mock_val_ser.py:58:
in _get_built
raise PydanticUserError(self._error_message, code=self._code)
E pydantic.errors.PydanticUserError:
`TypeAdapter[typing.Annotated[ForwardRef('Annotated[FilterParam[str | None],
param_depends]'), Query(PydanticUndefined)]]` is not fully defined; you should
define `typing.Annotated[ForwardRef('Annotated[FilterParam[str | None],
param_depends]'), Query(PydanticUndefined)]` and all referenced types, then
call `.rebuild()` on the instance.
E
E For further information visit
https://errors.pydantic.dev/2.11/u/class-not-fully-defined
```
So the only way here is to defined all the cases in the route statically.
--
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]