diff --git a/sentry_sdk/integrations/celery.py b/sentry_sdk/integrations/celery.py index 51fbad8fcb..0fd983de8d 100644 --- a/sentry_sdk/integrations/celery.py +++ b/sentry_sdk/integrations/celery.py @@ -167,7 +167,7 @@ def apply_async(*args, **kwargs): try: task_started_from_beat = args[1][0] == "BEAT" - except IndexError: + except (IndexError, TypeError): task_started_from_beat = False task = args[0] diff --git a/tests/integrations/celery/test_celery.py b/tests/integrations/celery/test_celery.py index bc2d36a619..0d44ee992e 100644 --- a/tests/integrations/celery/test_celery.py +++ b/tests/integrations/celery/test_celery.py @@ -593,3 +593,18 @@ def dummy_function(*args, **kwargs): ], headers={}, ) + + +def test_apply_async_no_args(init_celery): + celery = init_celery() + + @celery.task + def example_task(): + return "success" + + try: + result = example_task.apply_async(None, {}) + except TypeError: + pytest.fail("Calling `apply_async` without arguments raised a TypeError") + + assert result.get() == "success"