Skip to content

Commit 5b3a798

Browse files
Jeny SadadiaJenySadadia
authored andcommitted
api.db: fix Database.update method
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]>
1 parent 93c1c75 commit 5b3a798

File tree

1 file changed

+4
-3
lines changed

1 file changed

+4
-3
lines changed

api/db.py

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -278,9 +278,10 @@ async def update(self, obj):
278278
if obj.id is None:
279279
raise ValueError("Cannot update object with no id")
280280
col = self._get_collection(obj.__class__)
281-
obj.update()
282-
if obj.parent == obj.id:
283-
raise ValueError("Parent cannot be the same as the object")
281+
if obj.__class__ == Node:
282+
obj.update()
283+
if obj.parent == obj.id:
284+
raise ValueError("Parent cannot be the same as the object")
284285
res = await col.replace_one(
285286
{'_id': ObjectId(obj.id)}, obj.dict(by_alias=True)
286287
)

0 commit comments

Comments
 (0)