When unique constraint is violated status code is 409 #3569
Conversation
Hello @vdusek! Thanks for updating the PR. Cheers ! There are no PEP8 issues in this Pull Request. 🍻 Comment last updated on August 28, 2018 at 08:07 Hours UTC |
Can one of the admins verify this patch? |
This PR defines new exception to return 409 for uniqueness error. The test fails in the is_valid method because it catches or re-raises only generic ValidationError. So the exception I introduced is not handled properly. One of the solutions is to define our own is_valid method. But it doesn't seem to be a good solution. |
@vdusek I would write a custom is_valid method tht checks for the 409 and reraises it. If not a 409 it should just call into the super is_valid. |
Now, when unique constraint is violated the response looks like this:
Before the commit, with the ValidationError exception, it looked like this:
So the different format of the detail message is probably the reason why this test didn't pass. I spent a lot of time on figuring out how to format it in a right way but unsuccessfully. So if anyone has any idea how to do it, I'll be glad. |
Hi, thanks for the PR! Thanks, |
Codecov Report
@@ Coverage Diff @@
## master #3569 +/- ##
==========================================
+ Coverage 57.7% 58.33% +0.62%
==========================================
Files 60 61 +1
Lines 2523 2568 +45
==========================================
+ Hits 1456 1498 +42
- Misses 1067 1070 +3
Continue to review full report at Codecov.
|
Updated, checks finally passed. :) However it's not a final version, I'm going to open a PR on rest framework for a better solution. |
Opened issue - encode/django-rest-framework#6124 and PR - encode/django-rest-framework#6126 on DRF. However it doesn't seem like we're getting to a solution. |
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.
Thank you for pursuing the upstream option first, but as that isn't getting traction, your custom solution looks good, approved! (You'll still need someone w/ commit bit to approve in order to merge.)
I'm a bit hesitant on merging this PR. I don't think returning a 400 in cases where there is a uniqueness violation is incorrect. Moreover, I see a few downsides if we merge this:
|
@daviddavis You're probably right. The code isn't good, added value is not much and it could cause troubles in the future. I spent lot of time working on this issue but at least I learned something new. :) So I'll close this PR and the issue. |
@vdusek thanks for your hard work on this issue. Glad you were able to learn something too. 👍 |
closes #3846
https://pulp.plan.io/issues/3846