Fix integrity error handling#536
Conversation
|
Thanks for the pull request, @jesperhodge! This repository is currently maintained by Once you've gone through the following steps feel free to tag them in a comment and let them know that your changes are ready for engineering review. 🔘 Get product approvalIf you haven't already, check this list to see if your contribution needs to go through the product review process.
🔘 Provide contextTo help your reviewers and other members of the community understand the purpose and larger context of your changes, feel free to add as much of the following information to the PR description as you can:
🔘 Get a green buildIf one or more checks are failing, continue working on your changes until this is no longer the case and your build turns green. DetailsWhere can I find more information?If you'd like to get more details on all aspects of the review process for open source pull requests (OSPRs), check out the following resources: When can I expect my changes to be merged?Our goal is to get community contributions seen and reviewed as efficiently as possible. However, the amount of time that it takes to review and merge a PR can vary significantly based on factors such as:
💡 As a result it may take up to several weeks or months to complete a review and merge your PR. |
There was a problem hiding this comment.
@jesperhodge I agree that exception details should not be passed to the end user on a production site. However, it's useful behavior for developers. I'd expect the stack trace to be passed upwards when DEBUG==True, and a generic 500 to be shown when DEBUG==False.
Did you test with DEBUG==False? You can do django settings override, or just run the site with tutor local ....
|
To you other point:
yep, I agree. I think it's fine to either check for conflicts before renaming the tag, or use a very targeted |
|
I did have a look at openedx/openedx-platform#38246, an ADR in review that aims to standardize errors platform-wide. (Also reviewed it and left my thoughts.) I decided against implementing the proposed format more extensively here at this point, since there is still a lot to discuss around that. Rather, I think it makes sense that after that ADR is finalized we just implement a top-level CMS error handler, and this temporary solution in this PR can be removed at that time. |
|
To close the loop on this:
Jesper discussed in Slack that he did test with DEBUG==False, and he and Braden confirmed that this error detail leakage is a standing issue with DRF in general.
That approach sounds good to me @jesperhodge . Could you just include a link to the ADR PR in the temporary handlers so that we remember to remove them later? |
kdmccormick
left a comment
There was a problem hiding this comment.
Thanks for thinking this through and coming up with a stop-gap solution.
| @@ -4,12 +4,14 @@ | |||
| from __future__ import annotations | |||
There was a problem hiding this comment.
Thanks for the comprehensive tests.
e0475c8 to
6e25f2d
Compare
kdmccormick
left a comment
There was a problem hiding this comment.
Just one last request, and then we're good to merge. Thanks!
290fda5 to
3dd0700
Compare
3dd0700 to
d942235
Compare
|
Squashing as: |
| queryset = Tag.objects.filter(taxonomy_id=taxonomy_id, value=value) | ||
| if queryset.exists(): | ||
| raise serializers.ValidationError( | ||
| f'Tag value "{value}" already exists in this taxonomy.', code='unique' |
There was a problem hiding this comment.
Sorry @jesperhodge , I only just thought of this after merging:
Do these validation strings appear in the end user UI? If so, they need to be internationalized.
There was a problem hiding this comment.
Can you give me an example of how we do that?
As far as I see, we are not internationalizing a single error response in the whole repository.
I think since this is ubiquitous that would call for a new issue that has a bit wider scope and would include internationalizing other error messages like this. What do you think?
Is there any prior art in edx-platform?
There was a problem hiding this comment.
Hmm I had a quick look at edx-platform.
It seems like that in edx-platform, ValidationError messages forwarded to the frontend on edx-platform are also not internationalized, for example https://github.com/openedx/openedx-platform/blob/77293cdf8e97eddcb3db32624b690dff8fe5d0df/lms/djangoapps/badges/models.py#L15
There was a problem hiding this comment.
As far as I see, we are not internationalizing a single error response in the whole repository.
Ack, you're right, and it's worse than that--nothing in this repo is internationalized. And I guess we've noticed that before, too: #483 . No need for you to do anything here--we'll do a big sweep of internationalization at some point in the future. Thanks for checking on that.
would include internationalizing other error messages like this. What do you think?
I think the rule of thumb is "If the user will see it, it must be internationalized" rather than a blanket "all exceptions strings do/don't need to be internationalized".
Is there any prior art in edx-platform?
Yes, we use the standard gettext function for all translation. Usually we alias it to _:
from django.utils.translation import gettext as _
my_message = _("translate me")
my_template = _("hello {name}, translate me")There was a problem hiding this comment.
It seems like that in edx-platform, ValidationError messages forwarded to the frontend on edx-platform are also not internationalized, for example https://github.com/openedx/openedx-platform/blob/77293cdf8e97eddcb3db32624b690dff8fe5d0df/lms/djangoapps/badges/models.py#L15
That message is internationalized. The _ function returns the localized string, if it available.
There was a problem hiding this comment.
That message is internationalized. The _ function returns the localized string, if it available.
Oh! That's good
Fixes openedx/modular-learning#261
Idea right now:
Question: This would be better handled at the CMS level?
Answer: There is ongoing work to fix this up, starting with a proposal. See https://openedx.slack.com/archives/CHYH0BDTR/p1775053660743269 and openedx/openedx-platform#38246 in particular.