Browse Source

Fixes issue #4731 (#4762)

* Import default modules when running a report to avoid issues: issue/4731

* Updating CONTRIBUTORS.txt

* Add report command test to check import_default_modules call
Josue Balandrano Coronel 6 years ago
parent
commit
5a403a5eee
3 changed files with 43 additions and 1 deletions
  1. 2 1
      CONTRIBUTORS.txt
  2. 12 0
      celery/bin/celery.py
  3. 29 0
      t/unit/bin/test_report.py

+ 2 - 1
CONTRIBUTORS.txt

@@ -258,4 +258,5 @@ Alex Garel, 2018/01/04
 Régis Behmo 2018/01/20
 Igor Kasianov, 2018/01/20
 Derek Harland, 2018/02/15
-Chris Mitchell, 2018/02/27
+Chris Mitchell, 2018/02/27
+Josue Balandrano Coronel, 2018/05/24

+ 12 - 0
celery/bin/celery.py

@@ -355,6 +355,18 @@ class help(Command):
 class report(Command):
     """Shows information useful to include in bug-reports."""
 
+    def __init__(self, *args, **kwargs):
+        """Custom initialization for report command.
+
+        We need this custom initialization to make sure that
+        everything is loaded when running a report.
+        There has been some issues when printing Django's
+        settings because Django is not properly setup when
+        running the report.
+        """
+        super(report, self).__init__(*args, **kwargs)
+        self.app.loader.import_default_modules()
+
     def run(self, *args, **kwargs):
         self.out(self.app.bugreport())
         return EX_OK

+ 29 - 0
t/unit/bin/test_report.py

@@ -0,0 +1,29 @@
+# -*- coding: utf-8 -*-
+"""Tests for ``celery report`` command."""
+from __future__ import absolute_import, unicode_literals
+
+from case import Mock, call, patch
+
+from celery.bin.celery import report
+from celery.five import WhateverIO
+
+
+class test_report:
+    """Test report command class."""
+
+    def test_run(self):
+        out = WhateverIO()
+        with patch(
+            'celery.loaders.base.BaseLoader.import_default_modules'
+        ) as import_default_modules:
+            with patch(
+                'celery.app.base.Celery.bugreport'
+            ) as bugreport:
+                # Method call order mock obj
+                mco = Mock()
+                mco.attach_mock(import_default_modules, 'idm')
+                mco.attach_mock(bugreport, 'br')
+                a = report(app=self.app, stdout=out)
+                a.run()
+                calls = [call.idm(), call.br()]
+                mco.assert_has_calls(calls)