Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fixed put method when pk is an string #186

Merged
merged 1 commit into from
Oct 17, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion navigator/version.py
Original file line number Diff line number Diff line change
Expand Up @@ -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"
15 changes: 12 additions & 3 deletions navigator/views/model.py
Original file line number Diff line number Diff line change
Expand Up @@ -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={
Expand All @@ -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()
Expand Down
Loading