Skip to content

Commit

Permalink
Make rqstats -y fail when PyYAML is not installed (#660)
Browse files Browse the repository at this point in the history
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.
  • Loading branch information
SpecLad authored May 1, 2024
1 parent d33163d commit 87dd8cf
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 6 deletions.
4 changes: 2 additions & 2 deletions .github/workflows/test.yml
Original file line number Diff line number Diff line change
Expand Up @@ -33,8 +33,8 @@ jobs:
- name: Install dependencies
run: |
python -m pip install --upgrade pip
pip install django==${{ matrix.django-version }}
pip install redis django-redis rq sentry-sdk rq-scheduler
pip install django==${{ matrix.django-version }} \
redis django-redis pyyaml rq sentry-sdk rq-scheduler
- name: Run Test
run: |
Expand Down
8 changes: 4 additions & 4 deletions django_rq/management/commands/rqstats.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import click
import time

from django.core.management.base import BaseCommand
from django.core.management.base import BaseCommand, CommandError

from ...utils import get_statistics

Expand Down Expand Up @@ -85,9 +85,9 @@ def handle(self, *args, **options):
if options.get("yaml"):
try:
import yaml
except ImportError:
click.echo("Aborting. LibYAML is not installed.")
return
except ImportError as ex:
raise CommandError("PyYAML is not installed.") from ex

# Disable YAML alias
yaml.Dumper.ignore_aliases = lambda *args: True
click.echo(yaml.dump(get_statistics(), default_flow_style=False))
Expand Down

0 comments on commit 87dd8cf

Please sign in to comment.