Skip to content

Commit

Permalink
Primary key field should not be nullable (#1778)
Browse files Browse the repository at this point in the history
* Primary key field should not be nullable

* chore: update changelog
  • Loading branch information
LanceMoe authored Nov 19, 2024
1 parent f5c2c64 commit 762fe37
Show file tree
Hide file tree
Showing 2 changed files with 4 additions and 2 deletions.
2 changes: 1 addition & 1 deletion CHANGELOG.rst
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ Changelog
------
Fixed
^^^^^
- TODO
- Primary key field should not be nullable (#1778)

Added
^^^^^
Expand Down
4 changes: 3 additions & 1 deletion tortoise/contrib/pydantic/creator.py
Original file line number Diff line number Diff line change
Expand Up @@ -513,7 +513,9 @@ def _process_data_field(
ptype = python_type
if field.null:
json_schema_extra["nullable"] = True
if field_name in self._optional or field.default is not None or field.null:
if not field.pk and (
field_name in self._optional or field.default is not None or field.null
):
ptype = Optional[ptype]
if not (self._exclude_read_only and json_schema_extra.get("readOnly") is True):
return annotation or ptype
Expand Down

0 comments on commit 762fe37

Please sign in to comment.