Skip to content

Course assets should be served by a view rather than a middleware #34702

Closed

Description

@timmc-edx

Acceptance criteria:

  • StaticContentServer is converted from a middleware to a view
  • The cutover is managed with a Waffle flag or similar to allow careful rollout
  • Documentation added to next Open edX named-release notes
  • Optional: Additional cleanup
    • Remove temporary IMPL variable and StaticContentServer class by lifting methods to module scope
    • Separate views for different URL patterns

Course asset URLs like /asset-v1:... are served from a middleware at openedx.core.djangoapps.contentserver.middleware.StaticContentServer rather than from a view. This means that Django starts handling the request as a Not Found (because there is no matching urlpattern), but then the middleware intercepts the request and returns a response of its own. There wasn't any good reason for doing this instead of using a view, as far as I can tell. It causes some problems for telemetry: When the code-owner middleware asks Django what view handled the request, it does so by looking at the result of the resolve utility, but these URLs get a Resolver404 (because there's no registered urlpattern).

Implementation suggestion:

  1. Register equivalent urlpatterns and a view that calls into the same code the middleware currently contains.
  2. Add a Waffle flag that causes the middleware to fall through to the view.
  3. Try turning the flag on.
  4. Remove the middleware so that the view is always used.
  5. [Beyond this ticket:] Bring the new view's code up to standards (better use of urlpatterns, etc.)

PRs:

Activity

  1. kdmccormick commented on May 29, 2024

    @kdmccormick
    Member

    +1. This seriously confused Connor and I today!

  2. added
    maintenance
    code health
    on Jun 7, 2024
  3. timmc-edx commented on Jun 10, 2024

    @timmc-edx
    ContributorAuthor
  4. changed the title [-]Course assets are served by a middleware rather than a view[/-] [+]Course assets should be served by a view rather than a middleware[/+] on Jun 10, 2024
  5. robrap commented on Jun 11, 2024

    @robrap
    Contributor

    We don't actually own this, and it is no longer a high priority, but we might be able to help with rollout.

  6. moved this to Backlog in Arch-BOMon Jul 1, 2024
  7. jristau1984 commented on Aug 5, 2024

    @jristau1984
    Contributor

    @timmc-edx is this work complete, or is there anything left to do?

  8. 10 remaining items

  9. timmc-edx commented on Aug 8, 2024

    @timmc-edx
    ContributorAuthor

    edx.org has been converted over successfully. We'll let this bake for a week or two in production and then we can move the implementation properly into views.py and remove the old middleware.

  10. robrap commented on Aug 26, 2024

    @robrap
    Contributor

    @timmc-edx: FYI: I moving this out of blocked because it has sufficiently baked based on your last comment.

  11. moved this from Blocked to Ready For Development in Arch-BOMon Aug 26, 2024
  12. timmc-edx commented on Sep 10, 2024

    @timmc-edx
    ContributorAuthor

    This is largely complete, and now just wants a bit of optional cleanup. Acceptance criteria updated.

  13. timmc-edx commented on Sep 30, 2024

    @timmc-edx
    ContributorAuthor

    Closing out -- last bit of cleanup would involve turning this into three views, and probably isn't worth the effort right now.

  14. moved this from In Review to Done in Arch-BOMon Sep 30, 2024
  15. moved this from Done to Done - Long Term Storage in Arch-BOMon Nov 1, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

Labels

code healthmaintenance

Type

No type

Projects

No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions