identify_task crashes if user is deleted before execution
Nobody has claimed this yet.
- Dominant language
- Python
- Stars
- 39.9k
- Forks
- 3.4k
- Avg merge
- 6h 51m
- Merged PRs (30d)
- 232
Description
Bug Description
Description
The identify_task Celery task does not handle the case where a user is deleted before the task executes.
If the user is removed after the task is scheduled but before execution, User.objects.get(id=user_id) raises User.DoesNotExist, causing the task to fail.
This is a common race condition in async tasks.
How to reproduce
-
Schedule the task:
identify_task.delay(user.id) -
Delete the user before the task runs:
user.delete() -
When the worker executes the task, it raises
User.DoesNotExist
Expected behavior
The task should exit gracefully if the user no longer exists instead of failing.
Suggested fix
Wrap the lookup in a try/except:
try:
user = User.objects.get(id=user_id)
except User.DoesNotExist:
return
Debug info
- [ ] PostHog Cloud, Debug information: [please copy/paste from https://us.posthog.com/settings/project-details#variables or https://eu.posthog.com/settings/project-details#variables]
- [ ] PostHog Hobby self-hosted with `docker compose`, version/commit: [please provide]
- [ ] PostHog self-hosted with Kubernetes (deprecated, see [`Sunsetting Kubernetes support`](https://posthog.com/blog/sunsetting-helm-support-posthog)), version/commit: [please provide]
Contributor guide
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- Open a pull request that references the issue number.
Research direction
Start by locating the identify_task entry point and inspect how it looks up the user before execution. Confirm the behavior when the user has been deleted, then ensure the task exits gracefully instead of failing when the lookup cannot find a user.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- python
- Domain
- backend
- Issue type
- Bug
- Difficulty
- 2/5
- Estimated time
- 1-3 hours
- Activity status
- Quiet
- Clarity
- Clearly specified
- Newbie friendliness
- 72/100