Skip to content

Commit

Permalink
Fix attribute error caused by newest humanize package. (#1156)
Browse files Browse the repository at this point in the history
When accessing humanize.VERSION we were running into an attribute error since they removed VERSION from that file.
We are supposed to use the standard __version__ now.

Also set humanize package version in stone.
Modify message from bugreport function.
Add test confirming new bugreport behaviour.
  • Loading branch information
Tomasz-Kluczkowski authored Oct 19, 2021
1 parent 2cc15c1 commit 70b1ae4
Show file tree
Hide file tree
Showing 3 changed files with 15 additions and 6 deletions.
6 changes: 3 additions & 3 deletions flower/utils/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -20,11 +20,11 @@ def bugreport(app=None):
return 'flower -> flower:%s tornado:%s humanize:%s%s' % (
__version__,
tornado.version,
humanize.VERSION,
humanize.__version__,
app.bugreport()
)
except (ImportError, AttributeError):
return 'Unknown Celery version'
except (ImportError, AttributeError) as e:
return f"Error when generating bug report: {e}. Have you installed correct versions of Flower's dependencies?"


def abs_path(path):
Expand Down
2 changes: 1 addition & 1 deletion requirements/default.txt
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
celery>=5.0.5
tornado>=5.0.0,<7.0.0
prometheus_client>=0.8.0
humanize
humanize==3.12.0
pytz
13 changes: 11 additions & 2 deletions tests/unit/utils/test_utils.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import unittest
from unittest.mock import Mock

from flower.utils import bugreport
from celery import Celery
Expand All @@ -7,15 +8,23 @@
class BugreportTests(unittest.TestCase):
def test_default(self):
report = bugreport()
self.assertFalse('Unknown Celery version' in report)
self.assertFalse('Error when generating bug report' in report)
self.assertTrue('tornado' in report)
self.assertTrue('humanize' in report)
self.assertTrue('celery' in report)

def test_with_app(self):
app = Celery()
report = bugreport(app)
self.assertFalse('Unknown Celery version' in report)
self.assertFalse('Error when generating bug report' in report)
self.assertTrue('tornado' in report)
self.assertTrue('humanize' in report)
self.assertTrue('celery' in report)

def test_when_unable_to_generate_report(self):
fake_app = Mock()
fake_app.bugreport.side_effect = ImportError('import error message')
report = bugreport(fake_app)
self.assertTrue('Error when generating bug report' in report)
self.assertTrue('import error message' in report)
self.assertTrue("Have you installed correct versions of Flower's dependencies?" in report)

0 comments on commit 70b1ae4

Please sign in to comment.