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

[Bugfix:API] Fix DatetimeFieldOverflow error handling #3343

9 changes: 7 additions & 2 deletions mathesar/api/db/viewsets/records.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
from psycopg2.errors import ForeignKeyViolation, InvalidDatetimeFormat
from psycopg2.errors import ForeignKeyViolation, InvalidDatetimeFormat, DatetimeFieldOverflow
from rest_access_policy import AccessViewSetMixin
from rest_framework import status, viewsets
from rest_framework.exceptions import NotFound, MethodNotAllowed
Expand Down Expand Up @@ -103,11 +103,16 @@ def list(self, request, table_pk=None):
status_code=status.HTTP_400_BAD_REQUEST
)
except DataError as e:
if isinstance(e.orig, InvalidDatetimeFormat):
if isinstance(e.orig, (InvalidDatetimeFormat, DatetimeFieldOverflow)):
Anish9901 marked this conversation as resolved.
Show resolved Hide resolved
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please split these to raise InvalidDateFormatAPIException and InvalidDateAPIException respectively.

raise database_api_exceptions.InvalidDateFormatAPIException(
e,
status_code=status.HTTP_400_BAD_REQUEST,
)
else:
raise database_api_exceptions.RaiseExceptionAPIException(
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

MathesarAPIException would be more appropriate here, check the following for reference.

else:
raise database_api_exceptions.MathesarAPIException(e, status_code=status.HTTP_400_BAD_REQUEST)

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I have addressed all these changes that you mentioned in my latest commit.

e,
status_code=status.HTTP_500_INTERNAL_SERVER_ERROR
)

serializer = RecordSerializer(
records,
Expand Down