Skip to content

v0.4.2: (backport) Fix migration serialization for Pydantic constraints and dataclasses

Choose a tag to compare

@surenkov surenkov released this 14 Jan 17:58
ed2584d

(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