Skip to content

fix: return 400 instead of 500 when Course Live provider is unresolved - #39088

Open
taimoor-ahmed-1 wants to merge 2 commits into
openedx:masterfrom
edly-io:fix/course-live-lti-500
Open

taimoor-ahmed-1 wants to merge 2 commits into
openedx:masterfrom
edly-io:fix/course-live-lti-500

Conversation

@taimoor-ahmed-1

Copy link
Copy Markdown
Contributor

Description

CourseLiveConfigurationView.post dereferences provider before checking it, while the very next line already treats it as optional:

provider = ProviderManager().get_enabled_providers().get(request.data.get('provider_type', ''), None)
if not pii_sharing_allowed and provider.requires_pii_sharing():
    ...
if provider and not provider.additional_parameters and request.data.get('lti_configuration', False):

provider is None whenever provider_type is missing from the request or names a provider that is not enabled, so those requests raise an AttributeError and return 500 on a path the API documents as 400.

The existing test_post_error_messages does cover a missing provider_type, but it does not catch this: it creates CourseAllowPIISharingInLTIFlag first, which makes pii_sharing_allowed true and short-circuits the and before provider is ever touched. Without that flag — the default for a course — the dereference happens.

With the guard added, both cases fall through to the serializer, which already reports them correctly: "This field is required." for a missing provider_type, and "Provider type ... does not exist" for an unknown one.

Testing

Two regression tests, both exercising the no-PII-flag path the existing test does not reach:

  • test_post_missing_provider_type_without_pii_flag — empty payload, no flag → 400 with provider_type: ["This field is required."]
  • test_post_unknown_provider_type_without_pii_flag — an unrecognised provider_type, no flag → 400 with "does not exist"

I was not able to run the edx-platform suite locally (these tests need ModuleStoreTestCase and the full dev requirements), so I am relying on CI here — happy to adjust if the assertions need tightening.

Relationship to #39021

I found this while investigating #39021 (Course Live LTI 1.1 save returning 500 in Studio). It is not confirmed to be that issue's cause and I am not closing it. Two things do not line up: the reporter's first failure was PATCH /api/course_apps/v1/apps/{course_id}, a different endpoint from the one changed here, and they had selected a provider, so provider should not have been None for them.

For what it is worth, I did rule out the LTI consumer side of #39021: the Course Live save path (LtiConfiguration.objects.create(config_store=CONFIG_ON_DB) followed by a save with the LTI 1.1 fields) runs clean against both current xblock-lti-consumer master and the 11.4.0 that was released at the time of the report. Diagnosing #39021 properly still needs the server traceback behind those 500s.

This change stands on its own regardless: a documented 400 should not be a 500.

🤖 Generated with Claude Code

`CourseLiveConfigurationView.post` dereferences `provider` before checking
it, while the very next line already treats it as optional:

    provider = ProviderManager().get_enabled_providers().get(
        request.data.get('provider_type', ''), None)
    if not pii_sharing_allowed and provider.requires_pii_sharing():
    ...
    if provider and not provider.additional_parameters and ...

`provider` is None whenever `provider_type` is missing from the request or
names a provider that is not enabled, so those requests raise an
AttributeError and return 500 on a path the API documents as 400.

The existing `test_post_error_messages` covers a missing `provider_type`
but does not catch this, because it enables
`CourseAllowPIISharingInLTIFlag` first. That makes `pii_sharing_allowed`
true, which short-circuits the `and` before `provider` is touched. Without
the flag - the default for a course - the dereference happens.

With the guard in place both cases fall through to the serializer, which
already reports them properly: "This field is required." for a missing
`provider_type`, and "Provider type ... does not exist" for an unknown one.

Co-Authored-By: Claude Opus 5 <noreply@anthropic.com>
@openedx-webhooks

Copy link
Copy Markdown

Thanks for the pull request, @taimoor-ahmed-1!

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.

@openedx-webhooks openedx-webhooks added the open-source-contribution PR author is not from Axim or 2U label Sep 10, 2026
@github-project-automation github-project-automation Bot moved this to Needs Triage in Contributions Sep 10, 2026
@mphilbrick211 mphilbrick211 moved this from Needs Triage to Ready for Review in Contributions Sep 17, 2026
@mphilbrick211 mphilbrick211 added the needs reviewer assigned PR needs to be (re-)assigned a new reviewer label Nov 4, 2026

@Faraz32123 Faraz32123 left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Guard's right, but the serializer dereferences provider in two more places, so some payloads still 500. Ran these on your branch:

POST {"free_tier": true}
  views.py:140 -> serializers.py:126 validate_free_tier
  AttributeError: 'NoneType' object has no attribute 'has_free_tier'

POST {"enabled": true, "provider_type": "not_a_real_provider", "lti_configuration": {...}}
  views.py:140 -> serializers.py:40 validate_lti_config
  AttributeError: 'NoneType' object has no attribute 'requires_custom_email'

# `provider` is None when `provider_type` is missing or names a provider that is not
# enabled. Let the serializer report that as a 400 rather than raising an AttributeError
# here -- the check below already treats `provider` as optional.
if not pii_sharing_allowed and provider and provider.requires_pii_sharing():

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Passing a None provider down just moves the crash — see the two tracebacks in the review. The second one is the shape Studio posts for Zoom; line 127 skips the empty-config injection when provider is None, so the client's block reaches the validator.

Probably simplest to 400 right here when provider is None instead of leaving it to the serializer. Those two payloads would make good tests.

# enabled. Let the serializer report that as a 400 rather than raising an AttributeError
# here -- the check below already treats `provider` as optional.
if not pii_sharing_allowed and provider and provider.requires_pii_sharing():
return Response({

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Not your change, but it's the branch you're editing — this refusal falls through to a 200, so Studio reads a rejected save as success. HTTP_400_BAD_REQUEST is imported and unused right here. Fine as a separate PR.

The previous guard only stopped the PII check from dereferencing a None
provider. It then passed that None into the serializer context, where two more
dereferences wait, so the 500 moved rather than went away:

    POST {"free_tier": true}
      views.py -> serializers.py:126 validate_free_tier
      AttributeError: 'NoneType' object has no attribute 'has_free_tier'

    POST {"enabled": true, "provider_type": "not_a_real_provider",
          "lti_configuration": {...}}
      views.py -> serializers.py:40 validate_lti_config
      AttributeError: 'NoneType' object has no attribute 'requires_custom_email'

Both run during `is_valid()`, before `_update_course_live_instance` gets to
report the unknown provider, so neither payload ever reached the error it was
supposed to get. The second is the shape Studio posts for Zoom: the view skips
its empty-config injection when the provider is unresolved, so the client's own
`lti_config` block reaches the validator.

Reject the request in the view instead, as soon as the provider fails to
resolve. The response bodies are unchanged for the payloads that already
returned 400 -- a named but unknown provider still gets "Provider type X does
not exist", a missing one still gets the required-field error, and a blank one
still gets the non-blank field error.

With the provider guaranteed non-None past that point, the `provider and`
conjuncts it was threaded through are no longer needed.

Adds a regression test per payload, both verified to fail on the parent commit
at the two lines above.

This branch has not been deployed

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

Labels

needs reviewer assigned PR needs to be (re-)assigned a new reviewer open-source-contribution PR author is not from Axim or 2U

Projects

Status: Ready for Review

Development

Successfully merging this pull request may close these issues.

4 participants