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

Fix issue when post method on ModelView #316

Merged
merged 1 commit into from
Nov 19, 2024
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.11.5"
__version__ = "2.11.6"
__author__ = "Jesus Lara"
__author_email__ = "[email protected]"
__license__ = "BSD"
25 changes: 20 additions & 5 deletions navigator/views/model.py
Original file line number Diff line number Diff line change
Expand Up @@ -1145,11 +1145,18 @@ async def post(self):
status=202,
fields=fields
)
except Exception as exc:
print(exc, type(exc))
except NoDataFound:
### need to created:
qry = self.model(**data)
try:
qry = self.model(**data)
except (TypeError, ValidationError) as exc:
payload = getattr(exc, 'payload', None)
error = {
"message": f"Unable to insert over {self.__name__}",
"error": str(exc),
"payload": payload
}
return self.error(response=error, status=406)
if qry.is_valid():
try:
result = await qry.insert()
Expand All @@ -1168,7 +1175,7 @@ async def post(self):
)
else:
return self.error(
response=f"Unable to Insert over {self.__name__}",
response=f"Invalid Data for {self.__name__}",
)
except ModelError as ex:
error = {
Expand All @@ -1178,7 +1185,7 @@ async def post(self):
return self.error(response=error, status=400)
except DriverError as ex:
error = {
"message": f"{self.__name__} already exists",
"message": f"{self.__name__} {str(ex)}",
"error": str(ex),
}
return self.error(response=error, status=406)
Expand All @@ -1188,6 +1195,14 @@ async def post(self):
"payload": str(ex.payload),
}
return self.error(response=error, status=400)
except Exception as ex:
return self.error(
response={
"message": f"Unable to insert over {self.__name__}",
"error": str(ex)
},
status=406
)

async def _del_data(self, *args, **kwargs) -> Any:
"""_del_data.
Expand Down
Loading