From d30ecb09cce3c746d3aa3bcbf9955271281e6c06 Mon Sep 17 00:00:00 2001 From: David <9059044+Tansito@users.noreply.github.com> Date: Wed, 17 Jul 2024 17:03:33 -0400 Subject: [PATCH] Fix tasks initialization (#1414) --- gateway/api/apps.py | 26 +++++++++++++++----------- 1 file changed, 15 insertions(+), 11 deletions(-) diff --git a/gateway/api/apps.py b/gateway/api/apps.py index 208d6a3c4..b7bd5e799 100644 --- a/gateway/api/apps.py +++ b/gateway/api/apps.py @@ -4,6 +4,20 @@ from django.db.models.signals import post_migrate +def on_migrations_applied(sender, **kwargs): # pylint: disable=unused-argument + """ + This method will run tasks to populate the DB after the migration + """ + # This import may be here for the correct initialization of the App + from api.tasks import ( # pylint: disable=import-outside-toplevel + programs, + providers, + ) + + providers.assign_admin_group() + programs.assign_run_permission() + + class ApiConfig(AppConfig): """ApiConfig.""" @@ -11,14 +25,4 @@ class ApiConfig(AppConfig): name = "api" def ready(self): - def on_migrations_applied(**kwargs): - # This import may be here for the correct initialization of the App - from api.tasks import ( # pylint: disable=import-outside-toplevel - programs, - providers, - ) - - providers.assign_admin_group() - programs.assign_run_permission() - - post_migrate.connect(on_migrations_applied) + post_migrate.connect(on_migrations_applied, sender=self)