diff --git a/.github/workflows/code_quality.yaml b/.github/workflows/code_quality.yaml index 0a3af1d..9c9ee0b 100644 --- a/.github/workflows/code_quality.yaml +++ b/.github/workflows/code_quality.yaml @@ -5,6 +5,7 @@ on: push: branches: - 'release-*' + - 'improvement-*' jobs: qodana: diff --git a/panther/__init__.py b/panther/__init__.py index 463ca25..be7e06e 100644 --- a/panther/__init__.py +++ b/panther/__init__.py @@ -1,6 +1,6 @@ from panther.main import Panther # noqa: F401 -__version__ = '4.2.4' +__version__ = '4.2.5' def version(): diff --git a/panther/db/queries/mongodb_queries.py b/panther/db/queries/mongodb_queries.py index 3e468f2..9bfa43b 100644 --- a/panther/db/queries/mongodb_queries.py +++ b/panther/db/queries/mongodb_queries.py @@ -114,6 +114,8 @@ async def update(self, _update: dict | None = None, /, **kwargs) -> None: else: update_query['$set'] = update_query.get('$set', {}) update_query['$set'][field] = value + if isinstance(value, dict): + value = type(getattr(self, field))(**value) setattr(self, field, value) await db.session[self.__class__.__name__].update_one({'_id': self._id}, update_query) diff --git a/panther/db/queries/pantherdb_queries.py b/panther/db/queries/pantherdb_queries.py index caa2eae..a509026 100644 --- a/panther/db/queries/pantherdb_queries.py +++ b/panther/db/queries/pantherdb_queries.py @@ -96,6 +96,8 @@ async def update(self, _update: dict | None = None, /, **kwargs) -> None: self._validate_data(data=kwargs, is_updating=True) for field, value in document.items(): + if isinstance(value, dict): + value = type(getattr(self, field))(**value) setattr(self, field, value) db.session.collection(self.__class__.__name__).update_one({'_id': self._id}, **document) diff --git a/panther/db/queries/queries.py b/panther/db/queries/queries.py index 21bda24..dd51423 100644 --- a/panther/db/queries/queries.py +++ b/panther/db/queries/queries.py @@ -2,6 +2,7 @@ from typing import Sequence, Iterable from pantherdb import Cursor as PantherDBCursor +from pydantic import BaseModel from panther.configs import QueryObservable from panther.db.cursor import Cursor @@ -402,7 +403,12 @@ async def save(self) -> None: >>> user = User(name='Ali') >>> await user.save() """ - document = {field: getattr(self, field) for field in self.model_fields_set if field != 'request'} + document = { + field: getattr(self, field).model_dump() + if issubclass(type(getattr(self, field)), BaseModel) + else getattr(self, field) + for field in self.model_fields_set if field != 'request' + } if self.id: await self.update(document)