-
Notifications
You must be signed in to change notification settings - Fork 45
430 Fix bug with optional fields in custom forms #432
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from 12 commits
15f159e
91aa49b
a5500bf
c016a4b
4d8eef0
9d90273
a3bc19f
619f4fc
799f9b7
8b112d1
e3bfdee
05b5cf0
bc94e1b
ea38080
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,4 +1,9 @@ | ||
| import { type Schema, type OrderByConfig, getType } from "@/interfaces" | ||
| import { | ||
| type Schema, | ||
| type OrderByConfig, | ||
| getType, | ||
| isNullable | ||
| } from "@/interfaces" | ||
| import router from "./router" | ||
| import moment from "moment" | ||
|
|
||
|
|
@@ -140,6 +145,10 @@ export function convertFormValue(params: { | |
| if (value == "null") { | ||
| value = null | ||
| } else if (property.extra?.nullable && value == "") { | ||
| // TODO We can potentially remove this in the future - isNullable does | ||
| // what we need. | ||
| value = null | ||
| } else if (isNullable(property) && value == "") { | ||
|
||
| value = null | ||
| } else if (getType(property) == "array") { | ||
| value = JSON.parse(String(value)) | ||
|
|
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -100,13 +100,13 @@ class GroupItem(BaseModel): | |
|
|
||
|
|
||
| class GroupedTableNamesResponseModel(BaseModel): | ||
| grouped: t.Dict[str, t.List[str]] = Field(default_factory=list) | ||
| grouped: t.Dict[str, t.List[str]] = Field(default_factory=dict) | ||
| ungrouped: t.List[str] = Field(default_factory=list) | ||
|
|
||
|
|
||
| class GroupedFormsResponseModel(BaseModel): | ||
| grouped: t.Dict[str, t.List[FormConfigResponseModel]] = Field( | ||
| default_factory=list | ||
| default_factory=dict | ||
| ) | ||
| ungrouped: t.List[FormConfigResponseModel] = Field(default_factory=list) | ||
|
|
||
|
|
@@ -680,7 +680,7 @@ def __init__( | |
|
|
||
| private_app.add_route( | ||
| path="/change-password/", | ||
| route=change_password( | ||
| route=change_password( # type: ignore | ||
|
Member
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I'm pretty sure the Starlette type annotations are wrong here - we're just passing in a |
||
| login_url="./../../public/login/", | ||
| session_table=session_table, | ||
| read_only=read_only, | ||
|
|
@@ -786,7 +786,7 @@ def __init__( | |
|
|
||
| public_app.add_route( | ||
| path="/logout/", | ||
| route=session_logout(session_table=session_table), | ||
| route=session_logout(session_table=session_table), # type: ignore | ||
|
Member
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. See above about type annotations. |
||
| methods=["POST"], | ||
| ) | ||
|
|
||
|
|
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,55 @@ | ||
| import datetime | ||
| import typing as t | ||
|
|
||
| from pydantic import BaseModel | ||
| from starlette.requests import Request | ||
|
|
||
| from piccolo_admin.endpoints import FormConfig | ||
|
|
||
|
|
||
| class NullableFieldsModel(BaseModel): | ||
| """ | ||
| Used for testing a wide variety of field types. | ||
| """ | ||
|
|
||
| boolean_field: bool = True | ||
| boolean_field_nullable: t.Optional[bool] = None | ||
|
|
||
| float_field: float = 1.0 | ||
| float_field_nullable: t.Optional[float] = None | ||
|
|
||
| integer_field: int = 1 | ||
| integer_field_nullable: t.Optional[int] = None | ||
|
|
||
| string_field: str = "Hello world" | ||
| string_nullable: t.Optional[str] = None | ||
|
|
||
| list_field: t.List[str] = ["a", "b", "c"] | ||
| list_field_nullable: t.Optional[t.List[str]] = None | ||
|
|
||
| time_field: datetime.time = datetime.time(hour=12, minute=30) | ||
| time_field_nullable: t.Optional[datetime.time] = None | ||
|
|
||
| date_field: datetime.date = datetime.date(year=1999, month=12, day=31) | ||
| date_field_nullable: t.Optional[datetime.date] = None | ||
|
|
||
| datetime_field: datetime.datetime = datetime.datetime( | ||
| year=1999, month=12, day=31, hour=12, minute=30 | ||
| ) | ||
| datetime_field_nullable: t.Optional[datetime.datetime] = None | ||
|
|
||
| timedelta_field: datetime.timedelta = datetime.timedelta(hours=1) | ||
| timedelta_field_nullable: t.Optional[datetime.timedelta] = None | ||
|
|
||
|
|
||
| async def handle_form(request: Request, data: NullableFieldsModel) -> str: | ||
| return data.model_dump_json(indent=4) | ||
|
|
||
|
|
||
| FORM = FormConfig( | ||
| name="Nullable fields", | ||
| pydantic_model=NullableFieldsModel, | ||
| endpoint=handle_form, | ||
| description="Used for testing nullable fields.", | ||
| form_group="Test forms", | ||
| ) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It looks like Playwright isn't running out of the box on Ubuntu 24.04 at the moment due to some missing dependencies.
microsoft/playwright#30368