NewYour coding agent can read the release notes before it upgrades.Set up the MCP server →
PyPI
PyPI, #2753 most downloaded on PyPI
Type-Safe Pydantic Schemas for Django JSONFields
Latest stable
0.6.1
Last release 13 days ago
09 Nov 2026
Ships unpredictably
gaps range from 8 days to 8 months
Nearly every release is documented
notes for 54 of the last 60 stable releases
4 versions withdrawn
withdrawn after publishing
4 years old
75 releases · first in 2022
Drag across the ruler to compare, or tap a release to open it.
Fix 2-argument generic types in `PydanticSchemaField` (#105, #119): Resolves a django-stubs type error where annotating fields with 2-type-argument ge
PydanticSchemaField (#105, #119):
Resolves a django-stubs type error where annotating fields with 2-type-argument generics (e.g. field: dict[int, float] = SchemaField(), field: PydanticSchemaField[dict[int, float]]) caused django-stubs to mistakenly treat dict as Django's Field[Key, Value] and reject valid assignment types. PydanticSchemaField[_SchemaT, _GetT = _SchemaT] now declares two type parameters with PEP 696 defaults via typing_extensions.TypeVar in both fields.pyi and v1/fields.pyi.django-jsonform by injecting properties: {} and additionalProperties: true (#64).anyOf containing null and coerces empty string inputs to None for optional, nullable, and formatted fields (#65).anyOf and locking minItems/maxItems (#66).tests/test_forms.py.*-backports branches (#119).Full Changelog: https://github.com/surenkov/django-pydantic-field/compare/v0.6.0...v0.6.1
v0.6.1 Latest
Latest
Compare
Your coding agent can read these notes before it upgrades. Set up the MCP server →
This release adds drf-spectacular support, automatic field mapping in Django REST Framework's ModelSerializer , and configurable error handling ( erro
This release adds drf-spectacular support, automatic field mapping in Django REST Framework's ModelSerializer, and configurable error handling (errors="raise" | "ignore" | "coerce") for schema evolution. It also fixes OpenAPI 3.0.2 output in the built-in DRF AutoSchema and output_field handling on KeyTransform annotations.
drf-spectacular integration (#44, #113): PydanticSchemaFieldExtension generates OpenAPI schemas for SchemaField when using drf-spectacular. Install it with pip install django-pydantic-field[spectacular] and add "django_pydantic_field" to INSTALLED_APPS so DjangoPydanticFieldConfig registers the extension on startup.ModelSerializer field resolution (#6, #114): PydanticSchemaField is now registered in ModelSerializer.serializer_field_mapping and maps to rest_framework.SchemaField out of the box. On serializer classes, SchemaField can also be declared without arguments (field: SchemaType = SchemaField()), inferring its schema from the field annotation or the underlying model field.SchemaField now accepts errors: Literal["raise", "ignore", "coerce"] = "raise":
"raise" (default): raises ValidationError, which now includes params={"errors": ..., "field": ...}."ignore": returns the raw unparsed database value when validation fails so queries do not crash on legacy rows."coerce": falls back to the field's default or None (when null=True). Configuring errors="coerce" on a non-nullable field without a default emits the pydantic.W004 system check warning.output_field on KeyTransform (#80, #116): KeyTransform expressions in .annotate() now keep an explicitly provided output_field instead of falling back to the parent field's schema.AutoSchema (#113): Built-in AutoSchema adapters for Pydantic v1 and v2 now emit valid OpenAPI 3.0.2 schemas. v2 response schemas are wrapped in {"schema": ...}, non-JSON renderers like BrowsableAPIRenderer are excluded, v1 definitions are hoisted to #/components/schemas/, and $ref entries with sibling keys are wrapped in allOf.from_db_value() now routes pre-decoded driver values (such as psycopg dicts in .values() queries) through to_python(), and field.validate() raises Django's ValidationError instead of an uncaught pydantic.ValidationError.ModelSerializer output type: Previously, ModelSerializer had no mapping for PydanticSchemaField and fell back to DRF's JSONField, leaving raw dict or list values in serializer.validated_data. It now uses rest_framework.SchemaField and returns validated Pydantic instances.INSTALLED_APPS: Add "django_pydantic_field" to INSTALLED_APPS to register the ModelSerializer field mapping and drf-spectacular extension at startup.Full Changelog: v0.5.7...v0.6.0
v0.6.0: drf-spectacular integration, ModelSerializer support, and error handling
Compare
Fix 2-argument generic types in `PydanticSchemaField` (#105, #118): Backport of the fix resolving a django-stubs type error when annotating fields wit
(Backport release)
PydanticSchemaField (#105, #118):
Backport of the fix resolving a django-stubs type error when annotating fields with 2-type-argument generics (e.g. field: dict[int, float] = SchemaField(), field: PydanticSchemaField[dict[int, float]]). PydanticSchemaField[_SchemaT, _GetT = _SchemaT] now declares two type parameters with PEP 696 defaults via typing_extensions.TypeVar in both fields.pyi and v1/fields.pyi.*-backports branches.Full Changelog: https://github.com/surenkov/django-pydantic-field/compare/v0.5.7...v0.5.8
fix: prevent eager evaluation of callable defaults during system checks (#84) by @surenkov in https://github.com/surenkov/django-pydantic-field/pull/1
Full Changelog: https://github.com/surenkov/django-pydantic-field/compare/v0.5.6...v0.5.7
feat: support Python 3.15 by @surenkov in https://github.com/surenkov/django-pydantic-field/pull/109
Full Changelog: https://github.com/surenkov/django-pydantic-field/compare/v0.5.5...v0.5.6
Pydantic 2.14 Compatibility: Fixed an ImportError on Pydantic 2.14+ by falling back to pydantic.fields._Attrs when _DefaultValues is absent (#107, #10
ImportError on Pydantic 2.14+ by falling back to pydantic.fields._Attrs when _DefaultValues is absent (#107, #108 by @violuke).Full Changelog: https://github.com/surenkov/django-pydantic-field/compare/v0.5.4...v0.5.5
Fix migration mypy error. by @noamkush in https://github.com/surenkov/django-pydantic-field/pull/104
Full Changelog: https://github.com/surenkov/django-pydantic-field/compare/v0.5.3...v0.5.4
Refactored forward reference evaluation using typing-extensions to suppress DeprecationWarning regarding missing type_params.
Bug Fixes
UserWarning triggered by Pydantic v1 in Python 3.14.typing-extensions to suppress DeprecationWarning regarding missing type_params.Maintenance
ty version.type: ignore comments.Full Changelog: https://github.com/surenkov/django-pydantic-field/compare/v0.5.2...v0.5.3
Migration Serialization: Fixed an infinite recursion issue when serializing union types (e.g., list[Model] | None) in Django migrations on Python 3.11
Bug Fixes
list[Model] | None) in Django migrations on Python 3.11+. The fix wraps union arguments in a container to prevent Django’s IterableSerializer from recursing infinitely, ensuring migrations for complex schema fields are generated correctly.Improvements
SchemaField to better support nullable schemas (e.g., SchemaField(schema=MyModel | None, null=True)). This improves static analysis compatibility when defining nullable fields and their default values.Full Changelog: https://github.com/surenkov/django-pydantic-field/compare/v0.5.1...v0.5.2
Declare support for TypedDict protocols as valid schemas in SchemaField .
TypedDict protocols as valid schemas in SchemaField.conint, constr) and Annotated types using annotated_types or StringConstraints in Django migrations.RepresentationSerializer now correctly returns required imports.dataclass instances nested within generic containers (like list or dict) were not correctly wrapped for serialization.Full Changelog: v0.5.0...v0.5.1
v0.5.1: TypedDict support and Pydantic v2 migration fixes
Compare
The core adaptation logic is moved into a SchemaAdapter layer that handles both Pydantic v1 and v2 through the same interface.
The core adaptation logic is moved into a SchemaAdapter layer that handles both Pydantic v1 and v2 through the same interface.
SchemaAdapter, we’ve eliminated a lot of “if Pydantic v2 do this, else do that” code. This makes the field behavior identical regardless of which Pydantic version you are running..v1 subpackage..v1 subpackage:from django_pydantic_field.v1 import SchemaField as SchemaFieldV1uv for dependency management and building. This won’t affect library users, but it makes contributing easier.AutoSchema provided in django_pydantic_field.rest_framework.src/ layout. This shouldn’t affect standard installations, but if you were importing from internal file paths or using a non-standard setup, you may need to adjust your configuration.Full Changelog: v0.4.1...v0.5.0
v0.5.0: Architecture cleanup and better type hints
Compare
Pydantic v2 types like conint and StringConstraints use internal objects (e.g., annotated_types.Gt) that Django cannot serialize by default. By ensuri
(backport of 0.5.1 fix)
Pydantic v2 types like conint and StringConstraints use internal objects (e.g., annotated_types.Gt) that Django cannot serialize by default. By ensuring GenericContainer wraps these dataclass-like instances and fixing the RepresentationSerializer to return necessary imports, these types can now be used in Django migrations.
Addresses #72, but only for Pydantic v2. Pydantic v1 requires a different approach as it generates the ad-hoc constrained types, and in light of #35 and #71, not worth an effort.
Full Changelog: v0.4.1...v0.4.2
v0.4.2: (backport) Fix migration serialization for Pydantic constraints and dataclasses
Compare
Add support for Django 6.0 by @RealOrangeOne in #88
Full Changelog: v0.4.0...v0.4.1
Full Changelog: https://github.com/surenkov/django-pydantic-field/compare/v0.4.0...v0.4.1
Fixes for Python 3.14. by @noamkush in #85
Full Changelog: https://github.com/surenkov/django-pydantic-field/compare/v0.3.13...v0.4.0
Pydantic v2 types like conint and StringConstraints use internal objects (e.g., annotated_types.Gt) that Django cannot serialize by default. By ensuri
(backport of 0.5.1 fix)
Pydantic v2 types like conint and StringConstraints use internal objects (e.g., annotated_types.Gt) that Django cannot serialize by default. By ensuring GenericContainer wraps these dataclass-like instances and fixing the RepresentationSerializer to return necessary imports, these types can now be used in Django migrations.
Addresses #72, but only for Pydantic v2. Pydantic v1 requires a different approach as it generates the ad-hoc constrained types, and in light of #35 and #71, not worth an effort.
Full Changelog: v0.3.13...v0.3.14
v0.3.14: (backport) Fix migration serialization for Pydantic constraints and dataclasses
Compare
feat: fallback on json parsing in case of error by @quertenmont in https://github.com/surenkov/django-pydantic-field/pull/83
Full Changelog: https://github.com/surenkov/django-pydantic-field/compare/v0.3.12...v0.3.13
Drop Python 3.7, declare 3.13 support by @surenkov in https://github.com/surenkov/django-pydantic-field/pull/76
django.core.exceptions.ValidationError by @surenkov in https://github.com/surenkov/django-pydantic-field/pull/79from_db_value by @surenkov in https://github.com/surenkov/django-pydantic-field/pull/78Full Changelog: https://github.com/surenkov/django-pydantic-field/compare/v0.3.11...v0.3.12
fix ValidationError on empty form rendering by @amyasnikov in https://github.com/surenkov/django-pydantic-field/pull/75
Full Changelog: https://github.com/surenkov/django-pydantic-field/compare/v0.3.10...v0.3.11
Propagate allow_null parameter to base DRF Field by @surenkov in https://github.com/surenkov/django-pydantic-field/pull/70
allow_null parameter to base DRF Field by @surenkov in https://github.com/surenkov/django-pydantic-field/pull/70Full Changelog: https://github.com/surenkov/django-pydantic-field/compare/v0.3.9...v0.3.10
Bypass field validation on model instantiation if it does not contain a default= argument by @surenkov in https://github.com/surenkov/django-pydantic-
default= argument by @surenkov in https://github.com/surenkov/django-pydantic-field/pull/63Full Changelog: https://github.com/surenkov/django-pydantic-field/compare/v0.3.8...v0.3.9
Add django-jsonform widget incorporation for v2 fields by @surenkov in https://github.com/surenkov/django-pydantic-field/pull/59
django-jsonform widget incorporation for v2 fields by @surenkov in https://github.com/surenkov/django-pydantic-field/pull/59Full Changelog: https://github.com/surenkov/django-pydantic-field/compare/v0.3.7...v0.3.8
In 0.3.5, I introduced an incompatibility with Pydantic v1: particularly, importing pydantic_core unconditionally in compatibility layer . Thank you @
In 0.3.5, I introduced an incompatibility with Pydantic v1: particularly, importing pydantic_core unconditionally in compatibility layer :eyes:. Thank you @Abdullah0297445 for the bringing attention to this!
Both 0.3.5 and 0.3.6 were yanked from PyPI, I highly encourage to upgrade your pinned versions if you're the lucky one who has experienced this issue.
Full Changelog: https://github.com/surenkov/django-pydantic-field/compare/v0.3.6...v0.3.7
Use mode=json for get_prep_value during field value serialization by @surenkov in https://github.com/surenkov/django-pydantic-field/pull/57
mode=json for get_prep_value during field value serialization by @surenkov in https://github.com/surenkov/django-pydantic-field/pull/57Full Changelog: https://github.com/surenkov/django-pydantic-field/compare/v0.3.5...v0.3.6
Setup pre-commit by @surenkov in https://github.com/surenkov/django-pydantic-field/pull/53
pre-commit by @surenkov in https://github.com/surenkov/django-pydantic-field/pull/53typing.Annotated annotations by @surenkov in https://github.com/surenkov/django-pydantic-field/pull/52Full Changelog: https://github.com/surenkov/django-pydantic-field/compare/v0.3.4...v0.3.5
Prepare a SchemaField's default value to work with RootModel schemas by @surenkov in https://github.com/surenkov/django-pydantic-field/pull/51
default value to work with RootModel schemas by @surenkov in https://github.com/surenkov/django-pydantic-field/pull/51Full Changelog: https://github.com/surenkov/django-pydantic-field/compare/v0.3.3...v0.3.4
Allow (deprecated) django_pydantic_field.rest_framework.AutoSchema import with Pydantic 2.
Make sure all expected primitives are exposed during dynamic module resolution in compatibility layer.
Allow (deprecated) django_pydantic_field.rest_framework.AutoSchema import with Pydantic 2.
Full Changelog: https://github.com/surenkov/django-pydantic-field/compare/v0.3.2...v0.3.3
forms.SchemaField.to_python(): check if value already has a target type by @alexey-sveshnikov in https://github.com/surenkov/django-pydantic-field/pul
Full Changelog: https://github.com/surenkov/django-pydantic-field/compare/v0.3.1...v0.3.2
Full Changelog: https://github.com/surenkov/django-pydantic-field/compare/v0.3.1...v0.3.2b1
Full Changelog: https://github.com/surenkov/django-pydantic-field/compare/v0.3.1...v0.3.2b1
Add expressions handling for get_prep_value in v1 by @surenkov in https://github.com/surenkov/django-pydantic-field/pull/47
get_prep_value in v1 by @surenkov in https://github.com/surenkov/django-pydantic-field/pull/47Full Changelog: https://github.com/surenkov/django-pydantic-field/compare/v0.3.0...v0.3.1
This release centers on the incorporation of v2 primitives. In the earlier version, Pydantic v1, support was achieved through a series of workarounds
This release centers on the incorporation of v2 primitives. In the earlier version, Pydantic v1, support was achieved through a series of workarounds involving the manipulation of passed (or annotated) schemas. These schemas were wrapped into an intermediary RootModel to support both Pydantic models and most of the arbitrary annotations.
With v2, pydantic now ships a new primitive -- TypeAdapter -- which is well designed for this particular machinery.
To support both Pydantic v1 and v2, which might be useful during migration step, I added an indirection level during the import step.
0.3.0 contains implementations for both versions, with changes in v1 only required to make this compatibility layer to operate, with all behaviour remaining as in 0.2.13.
In 0.2.* versions, exact schema resolution had been done in three stages:
contribute_to_class method.In this update, I decided that evaluation logic should be as simple as possible, thus keeping only stage 3, and removing all the dirty logic that supported the machinery around 1 and 2 stages. To mitigate possible schema evaluation errors, which may appear only in runtime, the field now performs a few checks that are being performed by Django during app development lifecycle:
manage.py checkmanage.py runservermanage.py makemigrationsmanage.py migrateThis check is relied on the same mechanics that you might see in plain JSONField, complaining on passing mutable structures itself, instead of callables (Django's field.E010 warning).
Along with the schema evaluation check, the field now performes a few others, to make sure of its integrity:
pydantic.E001 (a check from the section above). The schema cannot be resolved. It is most likely a programmatic error -- forward references cannot be resolved in the Django model's execution context.pydantic.E002. The field's default= value cannot be serialized by the specified schema. This may lead to runtime errors during model .save() or .objects.create(...) methods.pydantic.E003. If the field contains include= or exclude= export arguments, there could be a situation that value, written in the database, could not be restored back to python from its serialized form. This check tries to pass the specified default value (or the one that could be inferred directly from the schema, if default= is missing), through the whole transformation cycle, yielding a warning if the value could not be transformed back to python.Additionally, JSONField's field.E010 warning is suppressed, as it is meaningless due to the nature of field transformations -- we're always getting a new value, not reusing the one passed to default= argument.
Full Changelog: https://github.com/surenkov/django-pydantic-field/compare/v0.2.14...v0.3.0
Django serialization support by @amyasnikov in https://github.com/surenkov/django-pydantic-field/pull/41
Full Changelog: https://github.com/surenkov/django-pydantic-field/compare/v0.3.0b1...v0.3.0b2
Full Changelog: https://github.com/surenkov/django-pydantic-field/compare/v0.3.0a5...v0.3.0b1
Full Changelog: https://github.com/surenkov/django-pydantic-field/compare/v0.3.0a5...v0.3.0b1
Add py.typed marker by @surenkov in https://github.com/surenkov/django-pydantic-field/pull/40
py.typed marker by @surenkov in https://github.com/surenkov/django-pydantic-field/pull/40Full Changelog: https://github.com/surenkov/django-pydantic-field/compare/v0.3.0a4...v0.3.0a5
Update README.md in https://github.com/surenkov/django-pydantic-field/pull/38;
Full Changelog: https://github.com/surenkov/django-pydantic-field/compare/v0.3.0a3...v0.3.0a4
Declare Django 5.0 support by @surenkov in https://github.com/surenkov/django-pydantic-field/pull/37
Full Changelog: https://github.com/surenkov/django-pydantic-field/compare/v0.3.0a2...v0.3.0a3
Previous pre-release contained a broken package. Here's the new one (:
Previous pre-release contained a broken package. Here's the new one (:
Full Changelog: https://github.com/surenkov/django-pydantic-field/compare/v0.3.0a1...v0.3.0a2
This release is specifically focused on adding v2 primitives. Pydantic v1 was supported by a trickery around passed (or annotated) schema, wrapping it
0.3.0a1 contained a broken package. Please take a look on 0.3.0a2 if you like to test it in the wild (:This release is specifically focused on adding v2 primitives. Pydantic v1 was supported by a trickery around passed (or annotated) schema, wrapping it into intermediary RootModel to support both pydantic models and most of arbitrary annotations.
With v2, pydantic now contains the primitive -- TypeAdapter -- which is well designed for this particular machinery.
There's one remaining primitive is to be migrated prior final 0.3.0 -- OpenAPI AutoSchema generator, but since this library is already not super-sticky to the OpenAPI standard, I decided that alpha release could be rolled out without it.
To support both Pydantic v1 and v2, which might be useful during migration step, I added an indirection level during the import step.
0.3.0 contains implementations for both versions, with changes in v1 only required to make this compatibility layer to operate, with all behaviour remaining as in 0.2.11.
In 0.2.* versions, exact schema resolution had been done in three stages:
contribute_to_class method.In this update, I decided that evaluation logic should be as simple as possible, thus keeping only stage 3, and removing all the dirty logic that supported the machinery around 1 and 2 stages. To mitigate possible schema evaluation errors, which may appear only in runtime, the field now performs a few checks that are being performed by Django during app development lifecycle:
manage.py checkmanage.py runservermanage.py makemigrationsmanage.py migrateThis check is relied on the same mechanics that you might see in plain JSONField, complaining on passing mutable structures itself, instead of callables (Django's field.E010 warning).
Along with the schema evaluation check, the field now performes a few others, to make sure of its integrity:
pydantic.E001 (a check from the section above). The schema cannot be resolved. It is most likely a programmatic error -- forward references cannot be resolved in the Django model's execution context.pydantic.E002. The field's default= value cannot be serialized by the specified schema. This may lead to runtime errors during model .save() or .objects.create(...) methods.pydantic.E003. If the field contains include= or exclude= export arguments, there could be a situation that value, written in the database, could not be restored back to python from its serialized form. This check tries to pass the specified default value (or the one that could be inferred directly from the schema, if default= is missing), through the whole transformation cycle, yielding a warning if the value could not be transformed back to python.Additionally, JSONField's field.E010 warning is suppressed, as it is meaningless due to the nature of field transformations -- we're always getting a new value, not reusing the one passed to default= argument.
Full Changelog: https://github.com/surenkov/django-pydantic-field/compare/v0.2.11...v0.3.0a1
Backport django.core.serializers support by @surenkov in https://github.com/surenkov/django-pydantic-field/pull/42
Full Changelog: https://github.com/surenkov/django-pydantic-field/compare/v0.2.13...v0.2.14
Add py.typed marker by @surenkov in https://github.com/surenkov/django-pydantic-field/pull/40
py.typed marker by @surenkov in https://github.com/surenkov/django-pydantic-field/pull/40Full Changelog: https://github.com/surenkov/django-pydantic-field/compare/v0.2.12...v0.2.13
Declare Django 5.0 support by @surenkov in https://github.com/surenkov/django-pydantic-field/pull/37
Full Changelog: https://github.com/surenkov/django-pydantic-field/compare/v0.2.11...v0.2.12
Preserve kwargs for json.dumps() by @fdemmer in https://github.com/surenkov/django-pydantic-field/pull/30
Full Changelog: https://github.com/surenkov/django-pydantic-field/compare/v0.2.10...v0.2.11
Raise ValidationError on form invalid JSON payload by @surenkov in https://github.com/surenkov/django-pydantic-field/pull/29
Full Changelog: https://github.com/surenkov/django-pydantic-field/compare/v0.2.9...v0.2.10
Ensure that attributes set during contribute_to_class are copied. by @TomTruck in https://github.com/surenkov/django-pydantic-field/pull/27
contribute_to_class are copied. by @TomTruck in https://github.com/surenkov/django-pydantic-field/pull/27Full Changelog: https://github.com/surenkov/django-pydantic-field/compare/v0.2.8...v0.2.9
Add backward support for pydantic 1.9.* by @surenkov in https://github.com/surenkov/django-pydantic-field/pull/26
Full Changelog: https://github.com/surenkov/django-pydantic-field/compare/v0.2.7...v0.2.8
Updates to deconstruct() in SchemaField to preserve values of include and exclude by @oomojola in https://github.com/surenkov/django-pydantic-field/pu
Full Changelog: https://github.com/surenkov/django-pydantic-field/compare/v0.2.6...v0.2.7
Bring back JSON field lookups to work with schema [Django 4.2] by @surenkov in https://github.com/surenkov/django-pydantic-field/pull/22
Full Changelog: https://github.com/surenkov/django-pydantic-field/compare/v0.2.5...v0.2.6
Add a bit of integration tests for models, forms and serializers by @surenkov in https://github.com/surenkov/django-pydantic-field/pull/17
get_prep_value and get_db_prep_value methods for PydanticSchemaField by @surenkov in https://github.com/surenkov/django-pydantic-field/pull/20This release fixes #19, thus Django < 4.2 users should avoid installing previous one, v0.2.4.
I'm considering to delist 0.2.4 from PyPI to minimize the potential harm.
Full Changelog: https://github.com/surenkov/django-pydantic-field/compare/v0.2.4...v0.2.5
Add support for Django 4.2 by @surenkov in https://github.com/surenkov/django-pydantic-field/pull/15
Full Changelog: https://github.com/surenkov/django-pydantic-field/compare/v0.2.3...v0.2.4
Migrate setup.cfg to the sole pyproject.toml by @surenkov in https://github.com/surenkov/django-pydantic-field/pull/13
setup.cfg to the sole pyproject.toml by @surenkov in https://github.com/surenkov/django-pydantic-field/pull/13__init__ before calling super().__init__ by @surenkov in https://github.com/surenkov/django-pydantic-field/pull/14Closed: https://github.com/surenkov/django-pydantic-field/issues/12
Full Changelog: https://github.com/surenkov/django-pydantic-field/compare/v0.2.2...v0.2.3
Test support for python 3.11 by @surenkov in https://github.com/surenkov/django-pydantic-field/pull/11
Full Changelog: https://github.com/surenkov/django-pydantic-field/compare/v0.2.1...v0.2.2
The package supports Django starting from 3.1.
The package supports Django starting from 3.1.
Full Changelog: https://github.com/surenkov/django-pydantic-field/compare/v0.2.0...v0.2.1
Python 3.7 + Django 3.2 support by @surenkov in https://github.com/surenkov/django-pydantic-field/pull/10
Full Changelog: https://github.com/surenkov/django-pydantic-field/compare/v0.1.13...v0.2.0
Django Forms schema field by @surenkov in https://github.com/surenkov/django-pydantic-field/pull/9
Full Changelog: https://github.com/surenkov/django-pydantic-field/compare/v0.1.12...v0.1.13
Un additin to typed collections and pydantic types, the field now also supports typing.Union, its special forms like typing.Optional and (only for py
Un additin to typed collections and pydantic types, the field now also supports typing.Union, its special forms like typing.Optional and (only for py 3.10+) X | Y union annotations syntax.
Full Changelog: https://github.com/surenkov/django-pydantic-field/compare/v0.1.11...v0.1.12
In the example below, typing linters should enforce type compatibility: ```python class BuildingMeta(pydantic.BaseModel): type: Optional[BuildingTypes
In the example below, typing linters should enforce type compatibility:
class BuildingMeta(pydantic.BaseModel):
type: Optional[BuildingTypes]
class Building(models.Model):
opt_meta: BuildingMeta = SchemaField(default={"type": "frame"}, null=True)
meta: Optional[BuildingMeta] = SchemaField(default={"type": "frame"})
Pyright will complain on both fields:
sample_app/models.py:5:32 - error: Expression of type "BuildingMeta | None" cannot be assigned to declared type "BuildingMeta"
sample_app/models.py:6:40 - error: Expression of type "ST@SchemaField" cannot be assigned to declared type "BuildingMeta | None"
Mypy has more broaden resolution for latter check, but still be able to recognise first one:
sample_app/models.py:5: error: Incompatible types in assignment (expression has type "Optional[BuildingMeta]", variable has type "BuildingMeta")
Fixing field annotations will resolve issues on both checkers:
class Building(models.Model):
opt_meta: Optional[BuildingMeta] = SchemaField(default={"type": "frame"}, null=True)
meta: BuildingMeta = SchemaField(default={"type": "frame"})
The check also enforces default=None to have null=True param.
default= argumentIn addition to null enforcement, typing checks allow arbitrary values for default= argument, as long as they are acceptable for pydantic's BaseModel.parse_obj method. Callables are also accepted, mimicking Django's field semantics.
Full Changelog: https://github.com/surenkov/django-pydantic-field/compare/v0.1.10...v0.1.11
Slightly improve inheritance chain, better typings for SchemaField factory function.
Slightly improve inheritance chain, better typings for SchemaField factory function.
Full Changelog: https://github.com/surenkov/django-pydantic-field/compare/v0.1.9...v0.1.10
Attempt to defer ForwardRefs resolution by @surenkov in https://github.com/surenkov/django-pydantic-field/pull/5
Full Changelog: https://github.com/surenkov/django-pydantic-field/compare/v0.1.8...v0.1.9
Django model fields are required to throw django.core.exceptions.ValidationError during .to_python(value) call. Let's stick to that recommendation.
Django model fields are required to throw django.core.exceptions.ValidationError during .to_python(value) call.
Let's stick to that recommendation.
Convert the input value into the expected Python data type, raising django.core.exceptions.ValidationError if the data can't be converted.
Nothing published for this version
I believe that initially introduced error_handler= param is basically doesn't make sense, as it breaks regular validation flow and could be even harmf
I believe that initially introduced error_handler= param is basically doesn't make sense, as it breaks regular validation flow and could be even harmful, as by default it simply suppress errors and writes them in logging. (Re)raising validation errors would be more explicit alternative to that.
One column per quarter.