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
added: exclusion violation custom error #3200
added: exclusion violation custom error #3200
Conversation
This comment was marked as resolved.
This comment was marked as resolved.
42b7fb7
to
58dd459
Compare
This comment was marked as resolved.
This comment was marked as resolved.
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.
Looking better! Yes, you want a test for this. I wouldn't bother using a CSV file. Create the fixture you need via psycopg calls. Read other fixtures for inspiration.
@manthan-jsharma Are you still planning to work on this? |
Certainly, I will be completing it. Currently, I am in the process of understanding how to import CSV files for the test cases. It would be helpful if you could provide guidance on this matter. Apart from that, the work is nearly finished. |
If you need help, please ask specific questions, taking care to explain exactly what problem you're having. Be clear about what steps you've taken, what expectation you have, and what observations you've made. If your questions are specific to the changes in this PR or are about implementation strategy, then the best place to ask is within this PR thread. However if your questions are more general questions about development processes and workflows, then it's probably better to ask in Matrix |
Hello @seancolsen and @dmos62, I have implemented the The code for the test case has been pushed in this commit: Link to the commit. @seancolsen and @dmos62, could you please guide me on how to write the expression for the exclusion constraint in this section of the code: Link to the code? Additionally, I am unsure if it is even possible to add the exclusion constraint using SQLAlchemy version 1.4.26. I couldn't find relevant information in the documentation; here is the link to the documentation: SQLAlchemy Documentation. |
@manthan-jsharma, |
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.
Hey @manthan-jsharma, I have requested some changes and addressed your queries in the code review please take a look at the specific comments.
db/constraints/base.py
Outdated
@@ -64,3 +64,20 @@ def get_constraint_def_json(self): | |||
} | |||
] | |||
) | |||
|
|||
|
|||
class ExclusionViolation(Constraint): |
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.
This class won't be necessary for now, the constraint classes that are defined in this file are the ones that we support , meaning, we allow DDL operations like CREATE
& DROP
and DQL operations like SELECT
. The issue you are solving is not to add support for this constraint but to handle any errors properly if violation for this constraint does occur on a table which has EXCLUSION
constraint on it.
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've removed the class
except TypeError: | ||
details = { | ||
"constraint": None, | ||
} |
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.
When does this occur?
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've just handled an edge case. This code will only execute in the event of a failure within the try block.
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.
Shouldn't that be handled using Exception
as it a base class for all the python exceptions instead of TypeError
? The TypeError
you have used here is a python type error and not a database type error.
exception_detail = get_default_exception_detail( | ||
exception, self.error_code, message, field, details | ||
)._asdict() | ||
self.detail = [exception_detail] | ||
self.status_code = status_code |
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.
use super()
instead.
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.
This is done, I've used super here
# table.add_constraint( | ||
# ExclusionViolation( | ||
# what parameters should i pass ? | ||
# ) | ||
# ) |
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.
You could just use raw SQL to add the required constraint for now.
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've attempted several SQL queries, but none of them seems to be working successful. Additionally, I couldn't find any examples in the documentation on how to add exclusion constraints using SQL. Could you please provide guidance on adding exclusion constraints in SQL here @Anish9901
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.
Try something similar to the SQL provided in the issue(#2126)
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.
As discussed, i am sharing the solution but it did not work.
- tried the query by directly using conn.execute, but got an error that
TSRANGE
is not defined. - tried by not using text from sqlalchemy but got an internal error from sqlalchemy library.
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.
You are facing this problem because the data type of the columns of the CSV are getting inferred as TEXT
instead of DATE
@@ -1464,3 +1464,33 @@ def test_record_patch_unique_violation(create_patents_table, client): | |||
f'/api/db/v0/tables/{table.id}/constraints/{constraint_id}/' | |||
).json() | |||
assert actual_constraint_details['name'] == 'NASA unique record PATCH_pkey' | |||
|
|||
|
|||
def test_record_patch_exclusion_violation(room_reservations_table, client): |
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 create a test case for POST
as well.
@manthan-jsharma I've added 12aa7e8 that takes care of the issues you were facing and the commit also include some general cleanups. Let me know if you have any concerns. |
1644ec5
Fixes #2126
Technical details
Screenshots
Checklist
Update index.md
).develop
branch of the repositoryvisible errors.
Developer Certificate of Origin
Developer Certificate of Origin