Skip to content

fix: swagger docs at /api-docs/ weren't loading due to ref_name conflict - #38994

Open
bradenmacdonald wants to merge 1 commit into
openedx:masterfrom
open-craft:braden/fix-swagger-docs
Open

fix: swagger docs at /api-docs/ weren't loading due to ref_name conflict#38994
bradenmacdonald wants to merge 1 commit into
openedx:masterfrom
open-craft:braden/fix-swagger-docs

Conversation

@bradenmacdonald

Copy link
Copy Markdown
Contributor

Description

The REST API docs site at http://local.openedx.io:8000/api-docs/ wasn't working on my devstack:

swagger-error
[14/Aug/2026 22:23:45] "GET /api-docs/?format=openapi HTTP/1.1" 500 474011
...
  File "/openedx/venv/lib/python3.12/site-packages/drf_yasg/inspectors/field.py", line 167, in field_to_swagger_object
    raise SwaggerGenerationError(
drf_yasg.errors.SwaggerGenerationError: Schema for <class 'openedx.core.djangoapps.enrollments.serializers.CourseEnrollmentSerializer'> would override distinct serializer <class 'lms.djangoapps.mobile_api.users.serializers.CourseEnrollmentSerializer'> because they implicitly share the same ref_name; explicitly set the ref_name attribute on both serializers' Meta classes

Cause

I believe the bug was introduced in #38724 .

drf-yasg derives an implicit ref_name by stripping the Serializer suffix from the class name. Both of these resolve to CourseEnrollment:

  • openedx/core/djangoapps/enrollments/serializers.py:71
  • lms/djangoapps/mobile_api/users/serializers.py:98

That 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 — through UserCourseEnrollmentsList (lms/djangoapps/mobile_api/users/views.py:372), a ListAPIView.

The enrollments one was never a serializer_class: every v1 view in openedx/core/djangoapps/enrollments/views.py is a plain APIView (invisible to drf-yasg's serializer introspection), and the one ListAPIView there uses the subclass CourseEnrollmentsApiListSerializer → ref_name CourseEnrollmentsApiList, which doesn't collide.

The mention PR added the new openedx/core/djangoapps/enrollments/v2/ app and mounted it unconditionally at lms/urls.py:121 (no waffle flag). Two of its views set the enrollments serializer as a first-class serializer_class:

  • EnrollmentViewSetopenedx/core/djangoapps/enrollments/v2/views.py:229
  • EnrollmentRetrieveViewopenedx/core/djangoapps/enrollments/v2/views.py:441

Now, both CourseEnrollment ref_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).

@bradenmacdonald
bradenmacdonald requested a review from a team as a code owner August 14, 2026 22:45
@openedx-webhooks

Copy link
Copy Markdown

Thanks for the pull request, @bradenmacdonald!

This repository is currently maintained by @openedx/wg-maintenance-openedx-platform-oncall.

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 approval

If you haven't already, check this list to see if your contribution needs to go through the product review process.

  • If it does, you'll need to submit a product proposal for your contribution, and have it reviewed by the Product Working Group.
    • This process (including the steps you'll need to take) is documented here.
  • If it doesn't, simply proceed with the next step.
🔘 Provide context

To 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:

  • Dependencies

    This PR must be merged before / after / at the same time as ...

  • Blockers

    This PR is waiting for OEP-1234 to be accepted.

  • Timeline information

    This PR must be merged by XX date because ...

  • Partner information

    This is for a course on edx.org.

  • Supporting documentation
  • Relevant Open edX discussion forum threads
🔘 Get a green build

If one or more checks are failing, continue working on your changes until this is no longer the case and your build turns green.

Details
Where 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:

  • The size and impact of the changes that it introduces
  • The need for product review
  • Maintenance status of the parent repository

💡 As a result it may take up to several weeks or months to complete a review and merge your PR.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

core contributor PR author is a Core Contributor (who may or may not have write access to this repo). open-source-contribution PR author is not from Axim or 2U

Projects

Status: Needs Triage

Development

Successfully merging this pull request may close these issues.

2 participants