Skip to content

Commit

Permalink
Merge branch 'main' into patch-1
Browse files Browse the repository at this point in the history
  • Loading branch information
mdomke authored Apr 2, 2024
2 parents d969966 + 2a249fc commit d5aaa20
Show file tree
Hide file tree
Showing 4 changed files with 27 additions and 2 deletions.
11 changes: 10 additions & 1 deletion CHANGELOG.rst
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,15 @@ Changelog

Versions follow `Semantic Versioning <http://www.semver.org>`_

`2.3.0`_ - 2023-09-21
`2.4.0`_ - 2024-04-02
---------------------

Added
~~~~~
* :class:`.ULID` objects are now properly serialized when used as Pydantic types `@Avihais12344 <https://github.com/Avihais12344>`_.


`2.3.0`_ - 2024-03-21
---------------------

Added
Expand Down Expand Up @@ -143,6 +151,7 @@ Changed
* The package now has no external dependencies.
* The test-coverage has been raised to 100%.

.. _2.4.0: https://github.com/mdomke/python-ulid/compare/2.3.0...2.4.0
.. _2.3.0: https://github.com/mdomke/python-ulid/compare/2.2.0...2.3.0
.. _2.2.0: https://github.com/mdomke/python-ulid/compare/2.1.0...2.2.0
.. _2.1.0: https://github.com/mdomke/python-ulid/compare/2.0.0...2.1.0
Expand Down
4 changes: 3 additions & 1 deletion pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -28,9 +28,11 @@ classifiers = [

[project.urls]
Homepage = "https://github.com/mdomke/python-ulid"
Changelog = "https://github.com/mdomke/python-ulid/releases"
Documentation = "https://python-ulid.readthedocs.io"
Changelog = "https://python-ulid.readthedocs.io/en/latest/changelog.html"
Issues = "https://github.com/mdomke/python-ulid/issues"
CI = "https://github.com/mdomke/python-ulid/actions"
Repository = "https://github.com/mdomke/python-ulid"

[project.optional-dependencies]
pydantic = [
Expand Down
11 changes: 11 additions & 0 deletions tests/test_ulid.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
import json
import time
import uuid
from collections.abc import Callable
Expand Down Expand Up @@ -177,3 +178,13 @@ class Model(BaseModel):
for value in [b"not-enough", "not-enough"]:
with pytest.raises(ValidationError):
Model(ulid=value)

model_dict = model.model_dump()
ulid_from_dict = model_dict["ulid"]
assert ulid_from_dict == ulid
assert isinstance(ulid_from_dict, ULID)
assert Model(**model_dict) == model

model_json = model.model_dump_json()
assert isinstance(json.loads(model_json)["ulid"], str)
assert Model.model_validate_json(model_json) == model
3 changes: 3 additions & 0 deletions ulid/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -261,6 +261,9 @@ def __get_pydantic_core_schema__(cls, source: Any, handler: GetCoreSchemaHandler
core_schema.no_info_plain_validator_function(ULID),
]
),
serialization=core_schema.to_string_ser_schema(
when_used="json-unless-none",
),
)

@classmethod
Expand Down

0 comments on commit d5aaa20

Please sign in to comment.