Skip to content

feat: add management command context manager filter - #39194

Open
rahulkanneri-2u wants to merge 9 commits into
openedx:masterfrom
rahulkanneri-2u:feat/management-command-contextmanager-filter
Open

rahulkanneri-2u wants to merge 9 commits into
openedx:masterfrom
rahulkanneri-2u:feat/management-command-contextmanager-filter

Conversation

@rahulkanneri-2u

@rahulkanneri-2u rahulkanneri-2u commented Oct 6, 2026 •

Copy link
Copy Markdown
Contributor

Description

Add a pluggable filter hook in manage.py so Django management command execution can be wrapped by configured Open edX filter pipelines. This provides a public integration point without embedding organization-specific monitoring logic in edx-platform.

This impacts Developers and Operators who configure or run Django management commands. There are no UI changes.

Supporting information

Private reference ticket: https://2u-internal.atlassian.net/browse/LP-1263

Testing instructions

  1. Run python manage.py lms check and verify the command completes normally when no filter pipeline is configured.
  2. Configure a pipeline step for org.openedx.management.command.contextmanager.requested.v1 that returns a context manager.
  3. Run a management command such as python manage.py lms check.
  4. Verify the pipeline receives the command name and service variant, and that the command executes within the returned context manager.

Deadline

None.

Other information

  • Depends on openedx/openedx-filters#400, which is merged and released as v3.16.0. requirements/edx/base.txt is pinned to openedx-filters==3.16.0..
  • No migrations, security, accessibility, or backport considerations.

@rahulkanneri-2u

Copy link
Copy Markdown
Contributor Author

Once openedx/openedx-filters#400 is merged and released, I will update this PR to use the public filter import, update the dependency as needed, mark the PR ready for review, and request final review.

@rahulkanneri-2u
rahulkanneri-2u marked this pull request as ready for review October 19, 2026 09:19
@rahulkanneri-2u

Copy link
Copy Markdown
Contributor Author

@pwnage101 @feanil Could you review this PR so I can take it forward? I have made the required changes after merging openedx/openedx-filters#400

@robrap robrap 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.

Used Claude to find some open issues from the last PR. In addition to the comments added:

  1. There is no test coverage. How challenging would that be?
  2. Claude wrote "Before django.setup(). Pipeline steps get imported before the app registry is ready. The merged filter docstring doesn't mention this. It belongs in a follow-up on openedx-filters, not in this PR." Does it make sense to update docs here and/or in openedx-filters about the timing?
  3. You could update the PR description to note that #400 is merged and released as v3.16.0.

Comment thread manage.py Outdated
Comment thread manage.py
@rahulkanneri-2u

rahulkanneri-2u commented Oct 20, 2026 •

Copy link
Copy Markdown
Contributor Author

Used Claude to find some open issues from the last PR. In addition to the comments added:

  1. There is no test coverage. How challenging would that be?
  2. Claude wrote "Before django.setup(). Pipeline steps get imported before the app registry is ready. The merged filter docstring doesn't mention this. It belongs in a follow-up on openedx-filters, not in this PR." Does it make sense to update docs here and/or in openedx-filters about the timing?
  3. You could update the PR description to note that ConnectionError: [Errno 111] Connection refused when running django-admin set_staff #400 is merged and released as v3.16.0.

@robrap thanks for the review, addressed in 3a21503:

  1. Tests: added openedx/core/tests/test_manage_py.py. It covers command name resolution (including skipping options like --verbosity 2), service variant, the no-argument fallback, and the command running inside the returned context manager.
  2. Import timing: documented in a comment in manage.py that the filter runs before django.setup(), so pipeline steps must not import models at module level. Should we also add this to the filter docstring in openedx-filters, or is the note here enough?
  3. PR description: updated to note that openedx-filters#400 is merged and released as v3.16.0.

@rahulkanneri-2u
rahulkanneri-2u force-pushed the feat/management-command-contextmanager-filter branch from c67fc22 to 3a21503 Compare October 20, 2026 12:05

@robrap robrap 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.

Can we add a min constraint to

"openedx-filters", # Open edX Filters from Hooks Extension Framework (OEP-50)
like other examples in the file, with appended comment about requirement?

@rahulkanneri-2u

Copy link
Copy Markdown
Contributor Author

Can we add a min constraint to

"openedx-filters", # Open edX Filters from Hooks Extension Framework (OEP-50)

like other examples in the file, with appended comment about requirement?

@robrap Added >=3.16.0 to the openedx-filters entry in pyproject.toml with a comment on why, and updated uv.lock to match.

@robrap
robrap requested a review from feanil October 22, 2026 13:11
@robrap

robrap commented Oct 22, 2026

Copy link
Copy Markdown
Contributor

@feanil: Let me know if you want to review this related PR, or if I should go ahead and merge. Thank you.

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

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants