Skip to content

Commit 5a403a5

Browse files
xirdnehOmer Katz
authored andcommitted
Fixes issue celery#4731 (celery#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
1 parent 0d97399 commit 5a403a5

File tree

3 files changed

+43
-1
lines changed

3 files changed

+43
-1
lines changed

CONTRIBUTORS.txt

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -258,4 +258,5 @@ Alex Garel, 2018/01/04
258258
Régis Behmo 2018/01/20
259259
Igor Kasianov, 2018/01/20
260260
Derek Harland, 2018/02/15
261-
Chris Mitchell, 2018/02/27
261+
Chris Mitchell, 2018/02/27
262+
Josue Balandrano Coronel, 2018/05/24

celery/bin/celery.py

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -355,6 +355,18 @@ def run(self, *args, **kwargs):
355355
class report(Command):
356356
"""Shows information useful to include in bug-reports."""
357357

358+
def __init__(self, *args, **kwargs):
359+
"""Custom initialization for report command.
360+
361+
We need this custom initialization to make sure that
362+
everything is loaded when running a report.
363+
There has been some issues when printing Django's
364+
settings because Django is not properly setup when
365+
running the report.
366+
"""
367+
super(report, self).__init__(*args, **kwargs)
368+
self.app.loader.import_default_modules()
369+
358370
def run(self, *args, **kwargs):
359371
self.out(self.app.bugreport())
360372
return EX_OK

t/unit/bin/test_report.py

Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
1+
# -*- coding: utf-8 -*-
2+
"""Tests for ``celery report`` command."""
3+
from __future__ import absolute_import, unicode_literals
4+
5+
from case import Mock, call, patch
6+
7+
from celery.bin.celery import report
8+
from celery.five import WhateverIO
9+
10+
11+
class test_report:
12+
"""Test report command class."""
13+
14+
def test_run(self):
15+
out = WhateverIO()
16+
with patch(
17+
'celery.loaders.base.BaseLoader.import_default_modules'
18+
) as import_default_modules:
19+
with patch(
20+
'celery.app.base.Celery.bugreport'
21+
) as bugreport:
22+
# Method call order mock obj
23+
mco = Mock()
24+
mco.attach_mock(import_default_modules, 'idm')
25+
mco.attach_mock(bugreport, 'br')
26+
a = report(app=self.app, stdout=out)
27+
a.run()
28+
calls = [call.idm(), call.br()]
29+
mco.assert_has_calls(calls)

0 commit comments

Comments
 (0)