Skip to content

Django doesn't run if you remove a rq job on app.ready #3100

Closed
@MHM5000

Description

@MHM5000

How do you use Sentry?

Sentry Saas (sentry.io)

Version

2.3.0

Steps to Reproduce

  1. You can simply clone https://github.com/MHM5000/sentry_bug and follow the instructions on readme
  2. or create a django project and an example_app app
  3. install and configure sentry, rq, redis, django-rq, django-scheduler, rq-scheduler
  4. add the following to your example_app/apps.py
from datetime import datetime

import django_rq
from django.apps import AppConfig
from rq.job import Job

from example_app.defaults import JOB_ID
from example_app.tasks import something


class ExampleAppConfig(AppConfig):
    default_auto_field = "django.db.models.BigAutoField"
    name = "example_app"

    def ready(self) -> None:
        scheduler = django_rq.get_scheduler()

        job = scheduler.schedule(
            scheduled_time=datetime.now(),
            func=something,
            id=JOB_ID,
            interval=10 * 60,
        )
        print("job", job)

        connection = django_rq.get_connection()

        job = Job.fetch(JOB_ID, connection=connection)
        job.delete()
  1. create example_app/defaults.py and add a JOB_ID='job_id' there.
  2. create example_app/tasks.py and a dummy something method

I'd recommend going with the first option: clone the test repo

Expected Result

your project running smoothly.
this issue didn't exist in 2.1.1

Actual Result

Traceback (most recent call last):
  File "/Users/mojtahedi/.pyenv/versions/3.11.7/lib/python3.11/threading.py", line 1045, in _bootstrap_inner
    self.run()
  File "/Users/mojtahedi/.local/share/virtualenvs/test_sentry_bug-gPib43ih/lib/python3.11/site-packages/sentry_sdk/integrations/threading.py", line 99, in run
    return _run_old_run_func()
           ^^^^^^^^^^^^^^^^^^^
  File "/Users/mojtahedi/.local/share/virtualenvs/test_sentry_bug-gPib43ih/lib/python3.11/site-packages/sentry_sdk/integrations/threading.py", line 94, in _run_old_run_func
    reraise(*_capture_exception())
  File "/Users/mojtahedi/.local/share/virtualenvs/test_sentry_bug-gPib43ih/lib/python3.11/site-packages/sentry_sdk/utils.py", line 1640, in reraise
    raise value
  File "/Users/mojtahedi/.local/share/virtualenvs/test_sentry_bug-gPib43ih/lib/python3.11/site-packages/sentry_sdk/integrations/threading.py", line 92, in _run_old_run_func
    return old_run_func(self, *a, **kw)
           ^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/Users/mojtahedi/.pyenv/versions/3.11.7/lib/python3.11/threading.py", line 982, in run
    self._target(*self._args, **self._kwargs)
  File "/Users/mojtahedi/.local/share/virtualenvs/test_sentry_bug-gPib43ih/lib/python3.11/site-packages/django/utils/autoreload.py", line 64, in wrapper
    fn(*args, **kwargs)
  File "/Users/mojtahedi/.local/share/virtualenvs/test_sentry_bug-gPib43ih/lib/python3.11/site-packages/django/core/management/commands/runserver.py", line 125, in inner_run
    autoreload.raise_last_exception()
  File "/Users/mojtahedi/.local/share/virtualenvs/test_sentry_bug-gPib43ih/lib/python3.11/site-packages/django/utils/autoreload.py", line 87, in raise_last_exception
    raise _exception[1]
  File "/Users/mojtahedi/.local/share/virtualenvs/test_sentry_bug-gPib43ih/lib/python3.11/site-packages/django/core/management/__init__.py", line 394, in execute
    autoreload.check_errors(django.setup)()
  File "/Users/mojtahedi/.local/share/virtualenvs/test_sentry_bug-gPib43ih/lib/python3.11/site-packages/django/utils/autoreload.py", line 64, in wrapper
    fn(*args, **kwargs)
  File "/Users/mojtahedi/.local/share/virtualenvs/test_sentry_bug-gPib43ih/lib/python3.11/site-packages/django/__init__.py", line 24, in setup
    apps.populate(settings.INSTALLED_APPS)
  File "/Users/mojtahedi/.local/share/virtualenvs/test_sentry_bug-gPib43ih/lib/python3.11/site-packages/django/apps/registry.py", line 124, in populate
    app_config.ready()
  File "/Users/mojtahedi/sandbox/test_sentry_bug/example_app/apps.py", line 29, in ready
    job.delete()
  File "/Users/mojtahedi/.local/share/virtualenvs/test_sentry_bug-gPib43ih/lib/python3.11/site-packages/rq/job.py", line 1251, in delete
    connection.delete(self.key, self.dependents_key, self.dependencies_key)
  File "/Users/mojtahedi/.local/share/virtualenvs/test_sentry_bug-gPib43ih/lib/python3.11/site-packages/redis/commands/core.py", line 1713, in delete
    return self.execute_command("DEL", *names)
           ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/Users/mojtahedi/.local/share/virtualenvs/test_sentry_bug-gPib43ih/lib/python3.11/site-packages/sentry_sdk/integrations/redis/_sync_common.py", line 72, in sentry_patched_execute_command
    cache_properties = _compile_cache_span_properties(
                       ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/Users/mojtahedi/.local/share/virtualenvs/test_sentry_bug-gPib43ih/lib/python3.11/site-packages/sentry_sdk/integrations/redis/modules/caches.py", line 32, in _compile_cache_span_properties
    key = _get_safe_key(redis_command, args, kwargs)
          ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/Users/mojtahedi/.local/share/virtualenvs/test_sentry_bug-gPib43ih/lib/python3.11/site-packages/sentry_sdk/integrations/redis/utils.py", line 56, in _get_safe_key
    key = ", ".join(args)
          ^^^^^^^^^^^^^^^
TypeError: sequence item 0: expected str instance, bytes found

Metadata

Metadata

Assignees

Labels

No labels
No labels

Type

No type

Projects

Status

No status

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions