-
-
Notifications
You must be signed in to change notification settings - Fork 338
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
[Bugfix:API] Fix DatetimeFieldOverflow error handling #3343
Conversation
Signed-off-by: Sahil Suman <[email protected]>
Signed-off-by: Sahil Suman <[email protected]>
Hey, @sahilsuman933 please add a test case for this. |
There is no need for an additional test case because there is already a test case that should cover this issue. You can verify this by checking the test case SRC: /mathesar/tests/api/test_record_api.py // @Anish9901 |
Was this the case while running the pytest as well? As from the video in the issue description it seems like the exception was getting thown the 2nd time someone tried to add an invalid date. |
Signed-off-by: Sahil Suman <[email protected]>
This is because the type of the column "Patent Expiration Date" in your dataset is
Ah, that makes sense. |
True. The issue was due to the data being of text type, preventing pytest detection. Please advise on how to proceed further. Should I make another PR related to it to address this issue or do you want me to do something else? Apart from that I have implemented the review changes that you requested. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I noticed a couple more things since my last review:
- We have a separate exception class for
DatetimeFieldOverlflow
namelyInvalidDateAPIException
. - I was able to reproduce the issue locally using our pytest test suite, and you should be adding a test case addressing this issue, the test case mentioned in your screenshot refer to record update instead of record search you can see the difference by noticing the patch and get requests.
Look attest_record_search
for reference.
mathesar/api/db/viewsets/records.py
Outdated
@@ -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)): |
There was a problem hiding this comment.
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.
mathesar/api/db/viewsets/records.py
Outdated
raise database_api_exceptions.InvalidDateFormatAPIException( | ||
e, | ||
status_code=status.HTTP_400_BAD_REQUEST, | ||
) | ||
else: | ||
raise database_api_exceptions.RaiseExceptionAPIException( |
There was a problem hiding this comment.
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.
mathesar/mathesar/api/serializers/records.py
Lines 62 to 63 in d375575
else: | |
raise database_api_exceptions.MathesarAPIException(e, status_code=status.HTTP_400_BAD_REQUEST) |
There was a problem hiding this comment.
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.
Signed-off-by: Sahil Suman <[email protected]>
@Anish9901 The test case is failing and it is because the |
That is expected, you'd need to change the column type in the test itself. mathesar/mathesar/tests/api/test_record_api.py Lines 1414 to 1415 in d375575
|
Signed-off-by: Sahil Suman <[email protected]>
@Anish9901 Now the tests related to invalid dates are passing. Thank you so much for your guidance :) |
Signed-off-by: Sahil Suman <[email protected]>
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Alright, looks good now @sahilsuman933. Thanks for your contribution!
bf04737
Fixes #3331
This change incorporates an additional error from psycopg2 within the try-catch exception block in DatetimeFieldOverflow to handle out-of-range date values. Due to this, we encountered an UnboundLocalError, which shouldn't have been the case; instead, it should have been an error in the format of InvalidDateFormatAPIException.
Screenshots
Error Message:
After implementing this error handling case:
Checklist
Update index.md
).develop
branch of the repositoryvisible errors.
Developer Certificate of Origin
Developer Certificate of Origin