Skip to content
Draft
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
2 changes: 1 addition & 1 deletion pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand Down
2 changes: 1 addition & 1 deletion src/air/forms.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
21 changes: 21 additions & 0 deletions tests/test_forms.py
Original file line number Diff line number Diff line change
Expand Up @@ -633,3 +633,24 @@ def custom_widget(

rendered = autoform.render()
assert str(rendered) == "<custom>"


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
4 changes: 2 additions & 2 deletions uv.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.