Skip to content
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: remove instructor info serializer validation #34802

Conversation

rayzhou-bit
Copy link
Contributor

@rayzhou-bit rayzhou-bit commented May 15, 2024

Description

This PR removes serializer validation for instructor_info on the course details authoring page. When instructor_info is not fetched properly, the api errors and does not return data to the page.

The typical form for instructor_info is:

"instructor_info": {
        "instructors": [
            {
                "name": "Instructor Name",
                "title": "",
                "organization: "",
                "image": "",
                "bio": ""
            }
        ]
    },

The simplest I've seen is:

"instructor_info": {}

I've also used Professeurs used in place of instructors.

Since instructor_info comes in so many forms, it is best to just leave it as a DictField with its children unvalidated.

Supporting information

https://2u-internal.atlassian.net/browse/TNL-11484

Testing instructions

Navigate to the course details page of a course and ensure it loads as expected.

@@ -40,7 +26,7 @@ class CourseDetailsSerializer(serializers.Serializer):
entrance_exam_enabled = serializers.CharField(allow_blank=True)
entrance_exam_id = serializers.CharField(allow_blank=True)
entrance_exam_minimum_score_pct = serializers.CharField(allow_blank=True)
instructor_info = InstructorsSerializer()
instructor_info = serializers.DictField(allow_empty=True)
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
instructor_info = serializers.DictField(allow_empty=True)
instructor_info = InstructorsSerializer(allow_empty=True)

I think that it makes sense to keep the serializer validation so that only the expected information comes through when it is present. I agree with allowing the serializer to be empty.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The problem I'm seeing with this is in the case when instructor_info isn't empty, we're not necessarily getting the instructors field.

I've seen the following, so I think it's possible to get instructors in other languages too.

"instructor_info": {
        "Professeurs": []
    }

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The MFE version of the schedule and details page does not allow for the instructor key to be saved in other languages. The frontend expects that the key is in English. The key in varying languages is a bug introduced in the legacy page because of how it handled translations.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I see... we still have some corrupt data due to the legacy page then. If we are turning off the MFE and using legacy from time to time due to issues, would it be better to accept the corrupt data for now? When the serializer runs into an issue, it entirely shuts down course details.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Adding allow_empty should fix the issue for when there is corrupt data. In the edge case that you pointed out, Proffesseurs is filtered out so instructor_info was empty. With this change, an empty dict will be sent via the API.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks like that specific code doesn't work but I get the general idea. I'll look into something that will pass checks.

@rayzhou-bit rayzhou-bit requested a review from KristinAoki May 15, 2024 18:40
@rayzhou-bit
Copy link
Contributor Author

@KristinAoki I set allow_null for instructor instead. Not sure why allow_null doesn't work for instructor_info but this should allow empty instructor_into

@rayzhou-bit rayzhou-bit merged commit 0fd3bde into master May 16, 2024
47 checks passed
@rayzhou-bit rayzhou-bit deleted the 2u/remove-course-details-page-instructor-info-serializer-validation branch May 16, 2024 17:47
@edx-pipeline-bot
Copy link
Contributor

2U Release Notice: This PR has been deployed to the edX staging environment in preparation for a release to production.

@edx-pipeline-bot
Copy link
Contributor

2U Release Notice: This PR has been deployed to the edX production environment.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants