Skip to content

Commit

Permalink
Fix an issue on nested models in update()
Browse files Browse the repository at this point in the history
  • Loading branch information
AliRn76 committed Jul 27, 2024
1 parent e4fc276 commit 131ec79
Show file tree
Hide file tree
Showing 4 changed files with 6 additions and 1 deletion.
1 change: 1 addition & 0 deletions .github/workflows/code_quality.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ on:
push:
branches:
- 'release-*'
- 'improvement-*'

jobs:
qodana:
Expand Down
2 changes: 1 addition & 1 deletion panther/__init__.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
from panther.main import Panther # noqa: F401

Check warning on line 1 in panther/__init__.py

View workflow job for this annotation

GitHub Actions / Qodana for Python

Unsatisfied package requirements

Package requirements 'python-jose', 'faker', 'coverage', 'pytest', 'cryptography\~=42.0', 'websockets', 'pymongo' are not satisfied

__version__ = '4.2.4'
__version__ = '4.2.5'


def version():
Expand Down
2 changes: 2 additions & 0 deletions panther/db/queries/mongodb_queries.py
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
2 changes: 2 additions & 0 deletions panther/db/queries/pantherdb_queries.py
Original file line number Diff line number Diff line change
Expand Up @@ -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)

Expand Down

0 comments on commit 131ec79

Please sign in to comment.