Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@
from collections.abc import Callable
from typing import Annotated

from pydantic import BeforeValidator, Field
from pydantic import BeforeValidator, Field, PositiveInt

from airflow.api_fastapi.core_api.base import BaseModel, StrictBaseModel

Expand All @@ -38,7 +38,7 @@ class BasePool(BaseModel):
"""Base serializer for Pool."""

pool: str = Field(serialization_alias="name")
slots: int
slots: PositiveInt
description: str | None = Field(default=None)
include_deferred: bool

Expand All @@ -65,7 +65,7 @@ class PoolPatchBody(StrictBaseModel):
"""Pool serializer for patch bodies."""

name: str | None = Field(default=None, alias="pool")
slots: int | None = None
slots: PositiveInt | None = None
description: str | None = None
include_deferred: bool | None = None

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11433,6 +11433,7 @@ components:
title: Name
slots:
type: integer
exclusiveMinimum: 0.0
title: Slots
description:
anyOf:
Expand Down Expand Up @@ -11476,6 +11477,7 @@ components:
slots:
anyOf:
- type: integer
exclusiveMinimum: 0.0
- type: 'null'
title: Slots
description:
Expand All @@ -11499,6 +11501,7 @@ components:
title: Name
slots:
type: integer
exclusiveMinimum: 0.0
title: Slots
description:
anyOf:
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4248,6 +4248,7 @@ export const $PoolBody = {
},
slots: {
type: 'integer',
exclusiveMinimum: 0,
title: 'Slots'
},
description: {
Expand Down Expand Up @@ -4310,7 +4311,8 @@ export const $PoolPatchBody = {
slots: {
anyOf: [
{
type: 'integer'
type: 'integer',
exclusiveMinimum: 0
},
{
type: 'null'
Expand Down Expand Up @@ -4355,6 +4357,7 @@ export const $PoolResponse = {
},
slots: {
type: 'integer',
exclusiveMinimum: 0,
title: 'Slots'
},
description: {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -259,6 +259,24 @@ class TestPatchPool(TestPoolsEndpoint):
],
},
),
# Negative slot number
(
POOL1_NAME,
{},
{"slots": -10},
422,
{
"detail": [
{
"ctx": {"gt": 0},
"input": -10,
"loc": ["body", "slots"],
"msg": "Input should be greater than 0",
"type": "greater_than",
},
],
},
),
# Partial body on default_pool
(
Pool.DEFAULT_POOL_NAME,
Expand Down Expand Up @@ -335,7 +353,8 @@ def test_should_respond_200(
if response.status_code == 422:
for error in body["detail"]:
# pydantic version can vary in tests (lower constraints), we do not assert the url.
del error["url"]
if "url" in error:
del error["url"]

assert body == expected_response
if response.status_code == 200:
Expand Down
10 changes: 7 additions & 3 deletions airflow-ctl/src/airflowctl/api/datamodels/generated.py
Original file line number Diff line number Diff line change
Expand Up @@ -614,11 +614,15 @@ class PoolBody(BaseModel):
extra="forbid",
)
name: Annotated[str, Field(max_length=256, title="Name")]
slots: Annotated[int, Field(title="Slots")]
slots: Annotated[int, Field(gt=0, title="Slots")]
description: Annotated[str | None, Field(title="Description")] = None
include_deferred: Annotated[bool | None, Field(title="Include Deferred")] = False


class Slots(RootModel[int]):
root: Annotated[int, Field(gt=0, title="Slots")]


class PoolPatchBody(BaseModel):
"""
Pool serializer for patch bodies.
Expand All @@ -628,7 +632,7 @@ class PoolPatchBody(BaseModel):
extra="forbid",
)
pool: Annotated[str | None, Field(title="Pool")] = None
slots: Annotated[int | None, Field(title="Slots")] = None
slots: Annotated[Slots | None, Field(title="Slots")] = None
description: Annotated[str | None, Field(title="Description")] = None
include_deferred: Annotated[bool | None, Field(title="Include Deferred")] = None

Expand All @@ -639,7 +643,7 @@ class PoolResponse(BaseModel):
"""

name: Annotated[str, Field(title="Name")]
slots: Annotated[int, Field(title="Slots")]
slots: Annotated[int, Field(gt=0, title="Slots")]
description: Annotated[str | None, Field(title="Description")] = None
include_deferred: Annotated[bool, Field(title="Include Deferred")]
occupied_slots: Annotated[int, Field(title="Occupied Slots")]
Expand Down