From 27a8b2ea67572aa9b516fa59bda8b7683e804a7c Mon Sep 17 00:00:00 2001 From: ktyagiapphelix2u Date: Thu, 26 Mar 2026 12:39:37 +0000 Subject: [PATCH 1/9] fix: add managemement command to filter hook --- manage.py | 28 +++++++++++++++++++++++++++- 1 file changed, 27 insertions(+), 1 deletion(-) diff --git a/manage.py b/manage.py index 9b8518937d48..fbbd40d0360a 100755 --- a/manage.py +++ b/manage.py @@ -23,6 +23,14 @@ import sys from argparse import ArgumentParser +from openedx_filters import OpenEdxPublicFilter + + +class ManagementCommandExecutionRequested(OpenEdxPublicFilter): + """Filter triggered before a management command is executed.""" + + FILTER_TYPE = 'org.openedx.platform.management.command.execute.requested.v1' + def parse_args(): """Parse edx specific arguments to manage.py""" @@ -96,4 +104,22 @@ def parse_args(): django_args.append('--help') from django.core.management import execute_from_command_line - execute_from_command_line([sys.argv[0]] + django_args) + + def command_runner(): + return execute_from_command_line([sys.argv[0]] + django_args) + + command_name = 'help' + if django_args and not django_args[0].startswith('-'): + command_name = django_args[0] + + try: + pipeline_output = ManagementCommandExecutionRequested.run_filter( + command_name=command_name, + service_variant=os.environ.get("SERVICE_VARIANT", edx_args.service_variant), + command_runner=command_runner, + ) + runner = pipeline_output.get('command_runner', command_runner) + except Exception: # pylint: disable=broad-except + runner = command_runner + + runner() From e0628c690ab8a12cf00902884891ff5b667b8139 Mon Sep 17 00:00:00 2001 From: ktyagiapphelix2u Date: Wed, 17 Jun 2026 06:19:44 +0000 Subject: [PATCH 2/9] fix: add managemement command to filter hook --- manage.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/manage.py b/manage.py index fbbd40d0360a..1dfbbfa54fe3 100755 --- a/manage.py +++ b/manage.py @@ -23,13 +23,13 @@ import sys from argparse import ArgumentParser -from openedx_filters import OpenEdxPublicFilter +from openedx_filters.tooling import OpenEdxPublicFilter class ManagementCommandExecutionRequested(OpenEdxPublicFilter): """Filter triggered before a management command is executed.""" - FILTER_TYPE = 'org.openedx.platform.management.command.execute.requested.v1' + filter_type = 'org.openedx.platform.management.command.execute.requested.v1' def parse_args(): From 8e3ba1deab52f28466228f6dc80e282da29d6651 Mon Sep 17 00:00:00 2001 From: ktyagiapphelix2u Date: Wed, 17 Jun 2026 07:12:40 +0000 Subject: [PATCH 3/9] fix: add managemement command to filter hook --- manage.py | 9 +++++++++ 1 file changed, 9 insertions(+) diff --git a/manage.py b/manage.py index 1dfbbfa54fe3..b7cf924ee6af 100755 --- a/manage.py +++ b/manage.py @@ -31,6 +31,15 @@ class ManagementCommandExecutionRequested(OpenEdxPublicFilter): filter_type = 'org.openedx.platform.management.command.execute.requested.v1' + @classmethod + def run_filter(cls, command_name, service_variant, command_runner): + """Run the management command execution pipeline.""" + return cls.run_pipeline( + command_name=command_name, + service_variant=service_variant, + command_runner=command_runner, + ) + def parse_args(): """Parse edx specific arguments to manage.py""" From 7503829b475bcf2b19fda2cf3be4b960ce521ce6 Mon Sep 17 00:00:00 2001 From: ktyagiapphelix2u Date: Mon, 20 Jul 2026 09:30:47 +0000 Subject: [PATCH 4/9] fix: add managemement command to filter hook --- manage.py | 12 +++++++++--- 1 file changed, 9 insertions(+), 3 deletions(-) diff --git a/manage.py b/manage.py index b7cf924ee6af..0ba4e77772d7 100755 --- a/manage.py +++ b/manage.py @@ -27,13 +27,17 @@ class ManagementCommandExecutionRequested(OpenEdxPublicFilter): - """Filter triggered before a management command is executed.""" + """ + Filter triggered before a management command is executed. + """ filter_type = 'org.openedx.platform.management.command.execute.requested.v1' @classmethod def run_filter(cls, command_name, service_variant, command_runner): - """Run the management command execution pipeline.""" + """ + Run the management command execution pipeline. + """ return cls.run_pipeline( command_name=command_name, service_variant=service_variant, @@ -42,7 +46,9 @@ def run_filter(cls, command_name, service_variant, command_runner): def parse_args(): - """Parse edx specific arguments to manage.py""" + """ + Parse edx specific arguments to manage.py + """ parser = ArgumentParser() subparsers = parser.add_subparsers(title='system', description='edX service to run') From 381a748e4d4f153e9fbd7a5f4d40464d945173df Mon Sep 17 00:00:00 2001 From: ktyagiapphelix2u Date: Thu, 23 Jul 2026 05:13:19 +0000 Subject: [PATCH 5/9] fix: add managemement command to filter hook --- manage.py | 20 ++++++++++---------- 1 file changed, 10 insertions(+), 10 deletions(-) diff --git a/manage.py b/manage.py index 0ba4e77772d7..b27a04ca41af 100755 --- a/manage.py +++ b/manage.py @@ -123,18 +123,18 @@ def parse_args(): def command_runner(): return execute_from_command_line([sys.argv[0]] + django_args) - command_name = 'help' - if django_args and not django_args[0].startswith('-'): - command_name = django_args[0] + command_name = next((arg for arg in django_args if not arg.startswith('-')), 'help') - try: - pipeline_output = ManagementCommandExecutionRequested.run_filter( - command_name=command_name, - service_variant=os.environ.get("SERVICE_VARIANT", edx_args.service_variant), - command_runner=command_runner, - ) + pipeline_output = ManagementCommandExecutionRequested.run_filter( + command_name=command_name, + service_variant=os.environ.get("SERVICE_VARIANT", edx_args.service_variant), + command_runner=command_runner, + ) + + runner = command_runner + if isinstance(pipeline_output, dict): runner = pipeline_output.get('command_runner', command_runner) - except Exception: # pylint: disable=broad-except + if not callable(runner): runner = command_runner runner() From 58afa1265e944795c8751cf5610c495a6208b120 Mon Sep 17 00:00:00 2001 From: Krish Tyagi Date: Tue, 28 Jul 2026 06:29:10 +0000 Subject: [PATCH 6/9] fix: add managemement command to filter hook --- manage.py | 43 +++++++++++++++++++++++++------------------ 1 file changed, 25 insertions(+), 18 deletions(-) diff --git a/manage.py b/manage.py index b27a04ca41af..db98590cc5a0 100755 --- a/manage.py +++ b/manage.py @@ -22,28 +22,38 @@ import os import sys from argparse import ArgumentParser +from contextlib import nullcontext from openedx_filters.tooling import OpenEdxPublicFilter -class ManagementCommandExecutionRequested(OpenEdxPublicFilter): +class ManagementCommandContextmanagerRequested(OpenEdxPublicFilter): """ Filter triggered before a management command is executed. + + Pipeline steps may provide a context manager to wrap command execution. """ - filter_type = 'org.openedx.platform.management.command.execute.requested.v1' + filter_type = 'org.openedx.platform.management.command.contextmanager.requested.v1' @classmethod - def run_filter(cls, command_name, service_variant, command_runner): + def run_filter(cls, command_contextmanager, command_name, service_variant): """ - Run the management command execution pipeline. + Run the management command context manager pipeline. """ - return cls.run_pipeline( + pipeline_output = cls.run_pipeline( + command_contextmanager=command_contextmanager, command_name=command_name, service_variant=service_variant, - command_runner=command_runner, ) + if isinstance(pipeline_output, dict): + contextmanager_result = pipeline_output.get('command_contextmanager', command_contextmanager) + if hasattr(contextmanager_result, '__enter__') and hasattr(contextmanager_result, '__exit__'): + return contextmanager_result + + return command_contextmanager + def parse_args(): """ @@ -120,21 +130,18 @@ def parse_args(): from django.core.management import execute_from_command_line - def command_runner(): - return execute_from_command_line([sys.argv[0]] + django_args) - + # django_args contains only the args that argparse did not consume. + # We treat the first non-option token as the Django command name. + # Example: django_args=['--verbosity', '2', 'migrate', '--noinput'] -> 'migrate'. + # If there is no non-option token (for example, django_args=['--help']), + # default to 'help' because Django will print command help in that case. command_name = next((arg for arg in django_args if not arg.startswith('-')), 'help') - pipeline_output = ManagementCommandExecutionRequested.run_filter( + command_contextmanager = ManagementCommandContextmanagerRequested.run_filter( + command_contextmanager=nullcontext(), command_name=command_name, service_variant=os.environ.get("SERVICE_VARIANT", edx_args.service_variant), - command_runner=command_runner, ) - runner = command_runner - if isinstance(pipeline_output, dict): - runner = pipeline_output.get('command_runner', command_runner) - if not callable(runner): - runner = command_runner - - runner() + with command_contextmanager: + execute_from_command_line([sys.argv[0]] + django_args) From ff6df4b583231c2a8dc9a0d37c25a9e7ac8073e7 Mon Sep 17 00:00:00 2001 From: Krish Tyagi Date: Wed, 29 Jul 2026 06:33:00 +0000 Subject: [PATCH 7/9] fix: add managemement command to filter hook --- manage.py | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/manage.py b/manage.py index db98590cc5a0..b175be5385f5 100755 --- a/manage.py +++ b/manage.py @@ -130,12 +130,12 @@ def parse_args(): from django.core.management import execute_from_command_line - # django_args contains only the args that argparse did not consume. - # We treat the first non-option token as the Django command name. - # Example: django_args=['--verbosity', '2', 'migrate', '--noinput'] -> 'migrate'. - # If there is no non-option token (for example, django_args=['--help']), - # default to 'help' because Django will print command help in that case. - command_name = next((arg for arg in django_args if not arg.startswith('-')), 'help') + # django_args contains only args that argparse did not consume. + # Django treats the first positional token as the command name. + # Example: django_args=['migrate', '--noinput'] -> 'migrate'. + # If the first token is an option (for example, django_args=['--help']), + # default to 'help' so the filter sees a command-like label. + command_name = django_args[0] if django_args and not django_args[0].startswith('-') else 'help' command_contextmanager = ManagementCommandContextmanagerRequested.run_filter( command_contextmanager=nullcontext(), From b9d910f3216e5155906765af5887e84421626595 Mon Sep 17 00:00:00 2001 From: Krish Tyagi Date: Thu, 30 Jul 2026 06:07:04 +0000 Subject: [PATCH 8/9] fix: add managemement command to filter hook --- manage.py | 41 +++++------------------------------------ 1 file changed, 5 insertions(+), 36 deletions(-) diff --git a/manage.py b/manage.py index b175be5385f5..95398b182f05 100755 --- a/manage.py +++ b/manage.py @@ -24,35 +24,7 @@ from argparse import ArgumentParser from contextlib import nullcontext -from openedx_filters.tooling import OpenEdxPublicFilter - - -class ManagementCommandContextmanagerRequested(OpenEdxPublicFilter): - """ - Filter triggered before a management command is executed. - - Pipeline steps may provide a context manager to wrap command execution. - """ - - filter_type = 'org.openedx.platform.management.command.contextmanager.requested.v1' - - @classmethod - def run_filter(cls, command_contextmanager, command_name, service_variant): - """ - Run the management command context manager pipeline. - """ - pipeline_output = cls.run_pipeline( - command_contextmanager=command_contextmanager, - command_name=command_name, - service_variant=service_variant, - ) - - if isinstance(pipeline_output, dict): - contextmanager_result = pipeline_output.get('command_contextmanager', command_contextmanager) - if hasattr(contextmanager_result, '__enter__') and hasattr(contextmanager_result, '__exit__'): - return contextmanager_result - - return command_contextmanager +from openedx_filters.management.filters import ManagementCommandContextmanagerRequested def parse_args(): @@ -130,14 +102,11 @@ def parse_args(): from django.core.management import execute_from_command_line - # django_args contains only args that argparse did not consume. - # Django treats the first positional token as the command name. - # Example: django_args=['migrate', '--noinput'] -> 'migrate'. - # If the first token is an option (for example, django_args=['--help']), - # default to 'help' so the filter sees a command-like label. - command_name = django_args[0] if django_args and not django_args[0].startswith('-') else 'help' + # First unconsumed argument is treated as the Django command name (e.g. 'migrate', 'runserver'). + # Falls back to 'no-argument' if django_args is empty. + command_name = django_args[0] if django_args else 'no-argument' - command_contextmanager = ManagementCommandContextmanagerRequested.run_filter( + command_contextmanager, _, _ = ManagementCommandContextmanagerRequested.run_filter( command_contextmanager=nullcontext(), command_name=command_name, service_variant=os.environ.get("SERVICE_VARIANT", edx_args.service_variant), From 09956fdb120b8d9e348e5ee5d359d175fbd1d6ee Mon Sep 17 00:00:00 2001 From: Krish Tyagi Date: Thu, 30 Jul 2026 06:32:34 +0000 Subject: [PATCH 9/9] fix: add managemement command to filter hook --- manage.py | 28 +++++++++++++++++++++++++++- 1 file changed, 27 insertions(+), 1 deletion(-) diff --git a/manage.py b/manage.py index 95398b182f05..44b95c719053 100755 --- a/manage.py +++ b/manage.py @@ -24,7 +24,33 @@ from argparse import ArgumentParser from contextlib import nullcontext -from openedx_filters.management.filters import ManagementCommandContextmanagerRequested +from openedx_filters.tooling import OpenEdxPublicFilter + + +class ManagementCommandContextmanagerRequested(OpenEdxPublicFilter): + """ + Filter triggered before a management command is executed. + + Pipeline steps may provide a context manager to wrap command execution. + """ + + filter_type = 'org.openedx.platform.management.command.contextmanager.requested.v1' + + @classmethod + def run_filter(cls, command_contextmanager, command_name, service_variant): + """ + Run the management command context manager pipeline. + """ + data = super().run_pipeline( + command_contextmanager=command_contextmanager, + command_name=command_name, + service_variant=service_variant, + ) + return ( + data.get('command_contextmanager', command_contextmanager), + data.get('command_name', command_name), + data.get('service_variant', service_variant), + ) def parse_args():