From 4c5764b58a129ce44234e0e7d958f69f8a6707d7 Mon Sep 17 00:00:00 2001 From: Jeny Sadadia Date: Tue, 26 Nov 2024 18:31:19 +0530 Subject: [PATCH] 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 --- api/db.py | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) diff --git a/api/db.py b/api/db.py index 38de4c86..c728a5e2 100644 --- a/api/db.py +++ b/api/db.py @@ -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) )