diff --git a/pyproject.toml b/pyproject.toml index bf28ae7a5..a80939fb5 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -86,7 +86,7 @@ keywords = [ ] dependencies = [ - "fastapi>=0.125.0", + "fastapi[standard]>=0.125.0", "itsdangerous>=2.2.0", "Jinja2>=3.1.6", "minify-html>=0.18.1", diff --git a/src/air/forms.py b/src/air/forms.py index d4c181efe..0828a7ab8 100644 --- a/src/air/forms.py +++ b/src/air/forms.py @@ -63,7 +63,7 @@ async def flight_form_depends(flight: Annotated[FlightForm, Depends(FlightForm.f """ model: type[BaseModel] | None = None - data: Any = None # TODO change type to something more specific + data: type[BaseModel] | None = None initial_data: dict | None = None errors: list[ErrorDetails] | None = None is_valid: bool = False diff --git a/tests/test_forms.py b/tests/test_forms.py index 8589e0670..de8a7394e 100644 --- a/tests/test_forms.py +++ b/tests/test_forms.py @@ -633,3 +633,24 @@ def custom_widget( rendered = autoform.render() assert str(rendered) == "" + + +def test_airform_rejects_non_basemodel_data() -> None: + """ + This ensures the type annotation data: type[BaseModel] | None is enforced + """ + + class NotABaseModel: + name: str + age: int + + class InvalidForm(air.AirForm): + model = NotABaseModel + + form = InvalidForm() + + # Should fail model is not a pydantic BaseModel type + with pytest.raises((TypeError, AttributeError)): + form.validate({"name": "Test", "age": 5}) + + assert not form.is_valid diff --git a/uv.lock b/uv.lock index 8f4e73d73..a9afb96cd 100644 --- a/uv.lock +++ b/uv.lock @@ -7,7 +7,7 @@ name = "air" version = "0.44.0" source = { editable = "." } dependencies = [ - { name = "fastapi" }, + { name = "fastapi", extra = ["standard"] }, { name = "frozendict" }, { name = "itsdangerous" }, { name = "jinja2" }, @@ -101,7 +101,7 @@ test = [ [package.metadata] requires-dist = [ - { name = "fastapi", specifier = ">=0.125.0" }, + { name = "fastapi", extras = ["standard"], specifier = ">=0.125.0" }, { name = "fastapi", extras = ["standard"], marker = "extra == 'standard'", specifier = ">=0.119.1" }, { name = "frozendict", specifier = ">=2.4.7" }, { name = "itsdangerous", specifier = ">=2.2.0" },