You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
I used the GitHub search to find a similar question and didn't find it.
I searched the SQLModel documentation, with the integrated search.
I already searched in Google "How to X in SQLModel" and didn't find any information.
I already read and followed all the tutorial in the docs and didn't find an answer.
I already checked if it is not related to SQLModel but to Pydantic.
I already checked if it is not related to SQLModel but to SQLAlchemy.
Commit to Help
I commit to help with one of those options 👆
Example Code
importuuidasuuid_pkgfromdatetimeimportdatetimefromtypingimportOptionalfrompydanticimportfield_validatorfromsqlmodelimportColumn, DateTime, Field, SQLModelclassHistorySCD2Base(SQLModel):
""" Base model for historical tracking. SCD Type 2 implementation. """# model_config = {# "json_schema_extra": {# "exclude": True# }# }h_group_id: uuid_pkg.UUID=Field(
default_factory=uuid_pkg.uuid4,
exclude=True,
index=True,
nullable=False,
description="Id of the group of historical records",
)
h_start_date: Optional[datetime] =Field(
default_factory=datetime.now,
exclude=True,
sa_column=Column(DateTime(timezone=False)),
)
h_end_date: Optional[datetime] =Field(
default_factory=datetime.now,
exclude=True,
sa_column=Column(DateTime(timezone=False)),
)
h_is_current: Optional[bool] =Field(
default=None,
exclude=True,
)
@field_validator("h_start_date", "h_end_date", mode="before")@classmethoddefparse_datetime(cls, v):
"""Parse ISO formatted datetime strings to datetime objects."""ifisinstance(v, str):
returndatetime.fromisoformat(v.replace("Z", "+00:00"))
returnvclassAddressBase(HistorySCD2Base):
"""Base model for addresses."""# ... fields of addresspassclassAddressUpdate(AddressBase):
"""Model for updating an address."""passclassAddress(AddressBase, table=True):
""" Database model for addresses. """__tablename__="addresses"# id and others
Description
Address-Input displays h_group_id and other fields that should be excluded from the schema
Problem description
The Address-Input component is displaying fields such as h_group_id (among others) that should not appear in the interface because they should be excluded from the schema. These fields are internal and not relevant to the end user, but are currently being rendered in /docs.
Expected behaviour
The component should respect the schema and not display fields marked as excluded or that are part of internal metadata.
Steps to reproduce
Load the form that uses the Address-Input component.
Observe the rendered fields.
Verify that h_group_id or other internal fields appear.
Impact
Causes confusion for the end user.
Displays internal information that should not be visible.
Proposed solution
Ensure that excluded fields are filtered before rendering.
Be able to differentiate between input and output exclusions in Pydantic models so that internal fields are not included in forms.
Introduce specific exclusion parameters to Field:
exclude: Excludes the field from both input schema and output serialization (internal fields).
exclude_input: Removes the field from the generated OpenAPI Input Schema (validation). Effectively makes the field "read-only" from the API client's perspective.
exclude_output: Removes the field from serialization (e.g., model_dump). Useful for secrets like passwords.
reacted with thumbs up emoji reacted with thumbs down emoji reacted with laugh emoji reacted with hooray emoji reacted with confused emoji reacted with heart emoji reacted with rocket emoji reacted with eyes emoji
Uh oh!
There was an error while loading. Please reload this page.
Uh oh!
There was an error while loading. Please reload this page.
-
First Check
Commit to Help
Example Code
Description
Address-Input displays
h_group_idand other fields that should be excluded from the schemaProblem description
The Address-Input component is displaying fields such as
h_group_id(among others) that should not appear in the interface because they should be excluded from the schema. These fields are internal and not relevant to the end user, but are currently being rendered in /docs.Expected behaviour
The component should respect the schema and not display fields marked as excluded or that are part of internal metadata.
Steps to reproduce
h_group_idor other internal fields appear.Impact
Proposed solution
exclude: Excludes the field from both input schema and output serialization (internal fields).exclude_input: Removes the field from the generated OpenAPI Input Schema (validation). Effectively makes the field "read-only" from the API client's perspective.exclude_output: Removes the field from serialization (e.g., model_dump). Useful for secrets like passwords.Operating System
Linux
Operating System Details
No response
SQLModel Version
0.0.27
Python Version
Python 3.13.9
Additional Context
Beta Was this translation helpful? Give feedback.
All reactions