PostHog / PostHog/posthog

Adding persons to a static cohort fails with a `500 Internal Server Error` in local development when the personhog path is active.

Open Beginner friendly
#57,744 0 comments 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

Bug description

Commit 5357ae3b695 introduced _insert_batch_via_personhog in posthog/models/cohort/cohort.py, which added a new ClickHouse SELECT query (_get_existing_ch_member_uuids) to deduplicate persons before insertion. This query runs without product/feature query tags, triggering UntaggedQueryError in DEBUG mode.

The error is DEBUG-only so it does not affect production.

How to reproduce

  1. Run local dev environment with personhog enabled
  2. Create a static cohort
  3. Try to add persons to it via the UI or PATCH /api/cohort/:id/add_persons
  4. Observe 500 Internal Server Error with traceback ending at posthog/models/cohort/cohort.py:848

Additional context

posthog.clickhouse.client.execute.UntaggedQueryError: sync_execute called with missing query tags: product, feature
  File "posthog/models/cohort/cohort.py", line 848, in _get_existing_ch_member_uuids

Root cause: _get_existing_ch_member_uuids calls sync_execute before insert_static_cohort (which already sets its own tags) gets a chance to run. Fix is to add tag_queries(product=ProductKey.COHORTS, feature=Feature.COHORT) in _insert_batch_via_personhog before the ClickHouse dedup check.

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]
- [x] PostHog Hobby self-hosted with `docker compose`, version/commit: ddf3ea88199088713a822ef064e1e58f44c50717
- [ ] 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 in posthog/models/cohort/cohort.py at _insert_batch_via_personhog and the _get_existing_ch_member_uuids call. Reproduce by enabling personhog and adding persons to a static cohort through the UI or PATCH /api/cohort/:id/add_persons, then inspect the ClickHouse query-tagging context. Done means the debug-only UntaggedQueryError and resulting 500 no longer occur.

Written by the indexing model from the issue text.

Assessment

Tech stack
clickhouse, python
Domain
backend, databases
Issue type
Bug
Difficulty
1/5
Estimated time
Under an hour
Activity status
Quiet
Clarity
Clearly specified
Newbie friendliness
78/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.