-
Notifications
You must be signed in to change notification settings - Fork 3.9k
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
fix: ORA response with attached file (for master) #33677
fix: ORA response with attached file (for master) #33677
Conversation
Thanks for the pull request, @DmytroAlipov! Please note that it may take us up to several weeks or months to complete a review and merge your PR. Feel free to add as much of the following information to the ticket as you can:
All technical communication about the code itself will be done via the GitHub pull request interface. As a reminder, our process documentation is here. Please let us know once your PR is ready for our review and all tests are green. |
10ac307
to
0232e82
Compare
@@ -196,6 +197,22 @@ class UploadedFileSerializer(serializers.Serializer): | |||
name = serializers.CharField() | |||
size = serializers.IntegerField() | |||
|
|||
def to_representation(self, instance): |
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.
Would it be possible instead to change the serializer of downloadURL? I'm thinking something along the lines of: downloadUrl = AbsoluteURLField(source="download_url")
Not sure if my proposition is better, or even possible at all.
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.
Do you mean something like this?
class AbsoluteURLField(serializers.URLField):
def to_representation(self, value):
if value and not value.startswith(("http://", "https://")):
return f"{settings.LMS_ROOT_URL}{value}"
return value
class UploadedFileSerializer(serializers.Serializer):
downloadUrl = AbsoluteURLField(source="download_url")
...
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.
We could use the existing openedx.core.lib.api.fields.AbsoluteURLField but that requires passing in the view's request
as context (see docs), and this isn't compatible with how UploadedFileSerializer
is constructed.
So I think it's ok to keep this change as-is.
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 wonder if you considered using SerializerMethodField
instead of overriding to_representation
. I tried this and it worked:
class UploadedFileSerializer(serializers.Serializer):
"""Serializer for a file uploaded as a part of a response"""
downloadUrl = serializers.SerializerMethodField(method_name="get_download_url")
description = serializers.CharField()
name = serializers.CharField()
size = serializers.IntegerField()
def get_download_url(self, obj):
"""
Get the representation for SerializerMethodField `downloadUrl`
"""
return urljoin(settings.LMS_ROOT_URL, obj["download_url"])
So, I'm curious about why this is the chosen approach. I want to be sure I'm not missing something. Thanks!
full_download_url = f"{settings.LMS_ROOT_URL}{download_url}" | ||
data["downloadUrl"] = full_download_url |
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.
full_download_url = f"{settings.LMS_ROOT_URL}{download_url}" | |
data["downloadUrl"] = full_download_url | |
data["downloadUrl"] = f"{settings.LMS_ROOT_URL}{download_url}" |
-
I think we could get rid of the
full_download_url
variable because it is used only once. -
Also, consider using
urljoin
for the absolute URL construction:
data["downloadUrl"] = urljoin(settings.LMS_ROOT_URL, download_url)
But be careful with expected URL parts (processing different cases with leading/trailing slashes (/
))
You can also use urljoin with two absolute URLs, so we could probably get rid of not download_url.startswith(("http://", "https://"))
check. But I suspect that it will be less readable. You can check some examples here
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 tried different options and they all work. I selected urljoin(settings.LMS_ROOT_URL, download_url)
. The nuances of use should not be a problem for us.
0232e82
to
8636958
Compare
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.
👍 @DmytroAlipov thank you for submitting this fix! It works perfectly.
I'm sorry it's taken so long to get reviewed. Unfortunately I'm not a core contributor for edx-platform, but I'll ping some people that are to see if we can get this and your backport PRs merged soon.
FYI @pkulkark @navinkarkera @farhaanbukhsh @MaferMazu @mariajgrimaldi
- I tested this on my devstack by following the instructions to enable frontend-app-ora-grading and view files uploaded to an ORA problem.
- I read through the code
- I checked for accessibility issues
- Includes documentation
- User-facing strings are extracted for translation
@@ -196,6 +197,22 @@ class UploadedFileSerializer(serializers.Serializer): | |||
name = serializers.CharField() | |||
size = serializers.IntegerField() | |||
|
|||
def to_representation(self, instance): |
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.
We could use the existing openedx.core.lib.api.fields.AbsoluteURLField but that requires passing in the view's request
as context (see docs), and this isn't compatible with how UploadedFileSerializer
is constructed.
So I think it's ok to keep this change as-is.
FYI @mphilbrick211 |
I'll review this one once I have a chance. Thanks @pomegranited for the ping :). After merging this one, I'll review the backport PRs as part of the BTR. Thanks folks! |
Hi @mariajgrimaldi! But in practice, this difference will be so small that it is almost unnoticeable. |
@mariajgrimaldi |
Sorry @pomegranited I was off when you pinged. @mariajgrimaldi Thank you for reviewing it and let me know if I can help you with the review. :) |
@DmytroAlipov: thanks for the detailed response! The implementation looks good to me; don't worry about changing it. Could you check the failing tests? |
@mariajgrimaldi I'm currently busy with other tasks, but I plan to deal with this PR early next week. |
@DmytroAlipov: don't worry. Please let me know when it's ready so we can merge :) |
0839d45
to
70fa522
Compare
After clicking the "View all responses" button in the ORA Staff Grading App, an error page appears for ORAs with file uploads.
70fa522
to
bb68e09
Compare
Hi @mariajgrimaldi! |
@DmytroAlipov 🎉 Your pull request was merged! Please take a moment to answer a two question survey so we can improve your experience in the future. |
Thank you so much @DmytroAlipov! |
2U Release Notice: This PR has been deployed to the edX staging environment in preparation for a release to production. |
2U Release Notice: This PR has been deployed to the edX production environment. |
Description
The details are described in this discussion.
Now everything works correctly:
Do not pay attention to the fact that the screenshot was taken from a local instance. It has been tested on the production server, and everything works just as correctly.