Skip to content

Commit

Permalink
api.db: fix Database.update method
Browse files Browse the repository at this point in the history
Database `update` method was breaking while creating a
`User` model with `is_superuser=1` field value.
Fix the method by separating `Node` specific logic from
other model updates based on below facts:
- `obj.update()` will trigger `BeanieBaseUser.update()` for `User`
model and not `DatabaseModel.update()`
- `User` model doesn't have `parent` field

Signed-off-by: Jeny Sadadia <[email protected]>
  • Loading branch information
Jeny Sadadia authored and JenySadadia committed Nov 27, 2024
1 parent 93c1c75 commit 5b3a798
Showing 1 changed file with 4 additions and 3 deletions.
7 changes: 4 additions & 3 deletions api/db.py
Original file line number Diff line number Diff line change
Expand Up @@ -278,9 +278,10 @@ async def update(self, obj):
if obj.id is None:
raise ValueError("Cannot update object with no id")
col = self._get_collection(obj.__class__)
obj.update()
if obj.parent == obj.id:
raise ValueError("Parent cannot be the same as the object")
if obj.__class__ == Node:
obj.update()
if obj.parent == obj.id:
raise ValueError("Parent cannot be the same as the object")
res = await col.replace_one(
{'_id': ObjectId(obj.id)}, obj.dict(by_alias=True)
)
Expand Down

0 comments on commit 5b3a798

Please sign in to comment.