PostHog / PostHog/posthog

identify_task crashes if user is deleted before execution

Open Beginner friendly
#54,525 1 comment 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

bug
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

  1. Schedule the task:

    identify_task.delay(user.id)
    
  2. Delete the user before the task runs: user.delete()

  3. 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

Open the contributing guide

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. 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

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.