Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

Closed
MHM5000 opened this issue May 23, 2024 · 4 comments · Fixed by #3101
Closed

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

MHM5000 opened this issue May 23, 2024 · 4 comments · Fixed by #3101
Assignees

Comments

@MHM5000
Copy link

MHM5000 commented May 23, 2024

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
@MHM5000 MHM5000 changed the title Django doesn't run if you remove a job on app.ready Django doesn't run if you remove a rq job on app.ready May 23, 2024
@antonpirker
Copy link
Member

Hey @MHM5000 ! Thanks for the bug report!

I think this was introduced in 2.3.0. Can you try to use 2.2.1 and confirm that it is working there?

@antonpirker
Copy link
Member

Released a fix for this in 2.3.1: https://github.com/getsentry/sentry-python/blob/master/CHANGELOG.md

@MHM5000
Copy link
Author

MHM5000 commented May 23, 2024

I didn't even have time to test 2.2.1
thanks for the quick fix @antonpirker

@allanlei
Copy link

allanlei commented May 24, 2024

We ran into this. Our workflow is using the redis broker with celery and flask. The error happens on celery.group() usage

task = celery.group([
    ..tasks..
]).apply_async()

task.get()
  • 2.2.1 does not have the error
  • 2.3.0 does have the error
  • 2.3.1 does not have the error

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
Archived in project
Development

Successfully merging a pull request may close this issue.

3 participants