From c7e8e9f2ebb9b613df5c172e70aba251026c8613 Mon Sep 17 00:00:00 2001 From: Jesus Lara Date: Wed, 18 Oct 2023 00:38:19 +0200 Subject: [PATCH] fixed put method when pk is an string --- navigator/version.py | 2 +- navigator/views/model.py | 15 ++++++++++++--- 2 files changed, 13 insertions(+), 4 deletions(-) diff --git a/navigator/version.py b/navigator/version.py index 67354a3b..9b929671 100644 --- a/navigator/version.py +++ b/navigator/version.py @@ -4,7 +4,7 @@ __description__ = ( "Navigator Web Framework based on aiohttp, " "with batteries included." ) -__version__ = "2.6.35" +__version__ = "2.6.36" __author__ = "Jesus Lara" __author_email__ = "jesuslarag@gmail.com" __license__ = "BSD" diff --git a/navigator/views/model.py b/navigator/views/model.py index 922a47fb..9b3c1a38 100644 --- a/navigator/views/model.py +++ b/navigator/views/model.py @@ -948,7 +948,11 @@ async def put(self): self.model.Meta.connection = conn try: result = await self.model.create(data) - return await self._model_response(result, status=201, fields=fields) + return await self._model_response( + result, + status=201, + fields=fields + ) except DriverError as ex: return self.error( response={ @@ -973,18 +977,23 @@ async def put(self): raise NoDataFound( "New Object" ) + if isinstance(self.pk, list): + _args = objid + else: + _args = {self.pk: objid} self.model.Meta.connection = conn - obj = await self.model.get(**objid) + obj = await self.model.get(**_args) await self._set_update(obj, data) result = await obj.update() status = 202 except NoDataFound: + # There is no data to update: obj = self.model(**data) # pylint: disable=E1102 obj.Meta.connection = conn if not obj.is_valid(): return self.error( response={ - "message": f"Invalid data for Schema {self.__name__}" + "message": f"Invalid data for {self.__name__}" } ) result = await obj.insert()