pierrejeambrun commented on code in PR #70124:
URL: https://github.com/apache/airflow/pull/70124#discussion_r4337745136
##########
airflow-core/src/airflow/api_fastapi/execution_api/routes/xcoms.py:
##########
@@ -190,6 +190,12 @@ def get_mapped_xcom_by_slice(
params: Annotated[GetXComSliceFilterParams, Query()],
session: SessionDep,
) -> XComSequenceSliceResponse:
+ if params.step == 0:
Review Comment:
Could we move this check into `GetXComSliceFilterParams` as a Pydantic
validator instead? FastAPI then turns it into its standard 422 response for us.
A plain `gt=0` constraint wouldn't work since negative steps are valid
(`seq[::-1]`), so something like:
```python
class GetXComSliceFilterParams(BaseModel):
"""Class to house slice params."""
start: int | None = None
stop: int | None = None
step: int | None = None
include_prior_dates: bool = False
previous_iteration: bool = False
@field_validator("step")
@classmethod
def validate_step(cls, step: int | None) -> int | None:
if step == 0:
raise ValueError("slice step cannot be zero")
return step
```
With that in place, `params.step or 1` below can stay as it was, since 0 can
no longer get there. The test would then check
`response.json()["detail"][0]["loc"] == ["query", "step"]`.
--
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]