fix: swagger docs at /api-docs/ weren't loading due to ref_name conflict - #38994
fix: swagger docs at /api-docs/ weren't loading due to ref_name conflict#38994bradenmacdonald wants to merge 1 commit into
Conversation
|
Thanks for the pull request, @bradenmacdonald! 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. |
Description
The REST API docs site at http://local.openedx.io:8000/api-docs/ wasn't working on my devstack:
Cause
I believe the bug was introduced in #38724 .
drf-yasg derives an implicit
ref_nameby stripping theSerializersuffix from the class name. Both of these resolve toCourseEnrollment:openedx/core/djangoapps/enrollments/serializers.py:71lms/djangoapps/mobile_api/users/serializers.py:98That name collision has existed for years and was harmless, because drf-yasg only introspects a serializer that a view actually exposes via
serializer_class/get_serializer_class(). Only the mobile one was reachable that way — throughUserCourseEnrollmentsList(lms/djangoapps/mobile_api/users/views.py:372), aListAPIView.The enrollments one was never a
serializer_class: every v1 view inopenedx/core/djangoapps/enrollments/views.pyis a plainAPIView(invisible to drf-yasg's serializer introspection), and the oneListAPIViewthere uses the subclassCourseEnrollmentsApiListSerializer→ ref_nameCourseEnrollmentsApiList, which doesn't collide.The mention PR added the new
openedx/core/djangoapps/enrollments/v2/app and mounted it unconditionally atlms/urls.py:121(no waffle flag). Two of its views set the enrollments serializer as a first-classserializer_class:EnrollmentViewSet—openedx/core/djangoapps/enrollments/v2/views.py:229EnrollmentRetrieveView—openedx/core/djangoapps/enrollments/v2/views.py:441Now, both
CourseEnrollmentref_names land in the same generated schema, and drf-yasg raises the error.Supporting information
n/a
Testing instructions
Go to http://local.openedx.io:8000/api-docs/ before and after this commit.
https://sandbox.opencraft.com/api-docs/ is our sandbox tracking master, and you can observe the error there ("before" case).