Skip to content

Commit 87dd8cf

Browse files
authored
Make rqstats -y fail when PyYAML is not installed (#660)
Currently, when PyYAML is not installed, `rqstats -y` prints an error message, but it still exits with a 0 exit code, indicating success. Fix that, along with a few related issues: * The error message was printed to stdout rather than stderr. * The name of the library in the message was incorrect (LibYAML is a C library; the Python library is PyYAML). After this change, you need to install PyYAML to run the testsuite, so modify the GitHub workflow accordingly. Also, make sure to install all packages at once, to make sure that later install commands don't overwrite the result of the earlier ones.
1 parent d33163d commit 87dd8cf

File tree

2 files changed

+6
-6
lines changed

2 files changed

+6
-6
lines changed

.github/workflows/test.yml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -33,8 +33,8 @@ jobs:
3333
- name: Install dependencies
3434
run: |
3535
python -m pip install --upgrade pip
36-
pip install django==${{ matrix.django-version }}
37-
pip install redis django-redis rq sentry-sdk rq-scheduler
36+
pip install django==${{ matrix.django-version }} \
37+
redis django-redis pyyaml rq sentry-sdk rq-scheduler
3838
3939
- name: Run Test
4040
run: |

django_rq/management/commands/rqstats.py

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
import click
22
import time
33

4-
from django.core.management.base import BaseCommand
4+
from django.core.management.base import BaseCommand, CommandError
55

66
from ...utils import get_statistics
77

@@ -85,9 +85,9 @@ def handle(self, *args, **options):
8585
if options.get("yaml"):
8686
try:
8787
import yaml
88-
except ImportError:
89-
click.echo("Aborting. LibYAML is not installed.")
90-
return
88+
except ImportError as ex:
89+
raise CommandError("PyYAML is not installed.") from ex
90+
9191
# Disable YAML alias
9292
yaml.Dumper.ignore_aliases = lambda *args: True
9393
click.echo(yaml.dump(get_statistics(), default_flow_style=False))

0 commit comments

Comments
 (0)