Skip to content

Commit

Permalink
Update pydantic to v2.x (#45)
Browse files Browse the repository at this point in the history
  • Loading branch information
omarudolley committed Oct 9, 2023
1 parent a51da80 commit 32218cb
Show file tree
Hide file tree
Showing 8 changed files with 171 additions and 64 deletions.
9 changes: 8 additions & 1 deletion CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,12 @@ this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.htm

## [Unreleased]

## [0.5.0] - 2023-10-09

### Changed

- Update pydantic from version 1.x to version 2.x

## [0.4.0] - 2023-10-03

### Added
Expand Down Expand Up @@ -192,7 +198,8 @@ this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.htm
- Update README.md
- Update .gitignore

[unreleased]: https://github.com/ioxiocom/firedantic/compare/0.4.0...HEAD
[unreleased]: https://github.com/ioxiocom/firedantic/compare/0.5.0...HEAD
[0.5.0]: https://github.com/ioxiocom/firedantic/compare/0.4.0...0.5.0
[0.4.0]: https://github.com/ioxiocom/firedantic/compare/0.3.0...0.4.0
[0.3.0]: https://github.com/ioxiocom/firedantic/compare/0.2.8...0.3.0
[0.2.8]: https://github.com/ioxiocom/firedantic/compare/0.2.7...0.2.8
Expand Down
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -162,7 +162,7 @@ from firedantic import AsyncModel, AsyncSubCollection, AsyncSubModel, ModelNotFo


class UserStats(AsyncSubModel):
id: Optional[str]
id: Optional[str] = None
purchases: int = 0

class Collection(AsyncSubCollection):
Expand Down
4 changes: 2 additions & 2 deletions firedantic/_async/model.py
Original file line number Diff line number Diff line change
Expand Up @@ -68,7 +68,7 @@ async def save(self) -> None:
:raise DocumentIDError: If the document ID is not valid.
"""
data = self.dict(by_alias=True)
data = self.model_dump(by_alias=True)
if self.__document_id__ in data:
del data[self.__document_id__]

Expand Down Expand Up @@ -279,7 +279,7 @@ class AsyncBareSubCollection(ABC):

@classmethod
def model_for(cls, parent, model_class):
parent_props = parent.dict(by_alias=True)
parent_props = parent.model_dump(by_alias=True)

name = model_class.__name__
ic = type(name, (model_class,), {})
Expand Down
4 changes: 2 additions & 2 deletions firedantic/_sync/model.py
Original file line number Diff line number Diff line change
Expand Up @@ -68,7 +68,7 @@ def save(self) -> None:
:raise DocumentIDError: If the document ID is not valid.
"""
data = self.dict(by_alias=True)
data = self.model_dump(by_alias=True)
if self.__document_id__ in data:
del data[self.__document_id__]

Expand Down Expand Up @@ -275,7 +275,7 @@ class BareSubCollection(ABC):

@classmethod
def model_for(cls, parent, model_class):
parent_props = parent.dict(by_alias=True)
parent_props = parent.model_dump(by_alias=True)

name = model_class.__name__
ic = type(name, (model_class,), {})
Expand Down
6 changes: 3 additions & 3 deletions firedantic/tests/tests_async/conftest.py
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ class CustomIDModel(AsyncBareModel):
__collection__ = "custom"
__document_id__ = "foo"

foo: Optional[str]
foo: Optional[str] = None
bar: str

class Config:
Expand All @@ -36,7 +36,7 @@ class CustomIDModelExtra(AsyncBareModel):
__collection__ = "custom"
__document_id__ = "foo"

foo: Optional[str]
foo: Optional[str] = None
bar: str
baz: str

Expand Down Expand Up @@ -181,7 +181,7 @@ async def _create(name: str, items: List[str]):

# Test case from README
class UserStats(AsyncSubModel):
id: Optional[str]
id: Optional[str] = None
purchases: int = 0

class Collection(AsyncSubCollection):
Expand Down
6 changes: 3 additions & 3 deletions firedantic/tests/tests_sync/conftest.py
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ class CustomIDModel(BareModel):
__collection__ = "custom"
__document_id__ = "foo"

foo: Optional[str]
foo: Optional[str] = None
bar: str

class Config:
Expand All @@ -36,7 +36,7 @@ class CustomIDModelExtra(BareModel):
__collection__ = "custom"
__document_id__ = "foo"

foo: Optional[str]
foo: Optional[str] = None
bar: str
baz: str

Expand Down Expand Up @@ -179,7 +179,7 @@ def _create(name: str, items: List[str]):

# Test case from README
class UserStats(SubModel):
id: Optional[str]
id: Optional[str] = None
purchases: int = 0

class Collection(SubCollection):
Expand Down
200 changes: 150 additions & 50 deletions poetry.lock

Large diffs are not rendered by default.

4 changes: 2 additions & 2 deletions pyproject.toml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
[tool.poetry]
name = "firedantic"
version = "0.4.0"
version = "0.5.0"
description = "Pydantic base models for Firestore"
authors = ["IOXIO Ltd"]
license = "BSD-3-Clause"
Expand All @@ -12,7 +12,7 @@ packages = [

[tool.poetry.dependencies]
python = ">=3.8.1,<4.0"
pydantic = "^1.10.13"
pydantic = "^2.4.2"
grpcio = "^1.59.0"
google-cloud-firestore = "^2.12.0"

Expand Down

0 comments on commit 32218cb

Please sign in to comment.