Skip to content

Conversation

@haacked
Copy link
Contributor

@haacked haacked commented Nov 22, 2025

Problem

The flags hypercache uses the team id in the cache key. It should be the project id. In practice this is not an issue because these values are the same, but maybe sometime in the future, they will not be.

Changes

Changed the way we build the key to use the project id.

How did you test this code?

Unit Tests

👉 Stay up-to-date with PostHog coding conventions for a smoother review.

Changelog: (features only) Is this feature complete?

Copilot AI review requested due to automatic review settings November 22, 2025 01:51
@posthog-bot posthog-bot requested a review from a team November 22, 2025 01:51
@posthog-project-board-bot posthog-project-board-bot bot moved this to In Review in Feature Flags Nov 22, 2025
Copy link
Contributor

@greptile-apps greptile-apps bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

2 files reviewed, 1 comment

Edit Code Review Agent Settings | Greptile

else:
if isinstance(key, Team):
key = key.id
key = key.project_id
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

logic: potential inconsistency: when an integer is passed as key, it's used directly in the cache key. but when a Team object is passed, project_id is used. if callers mix passing team.id (integer) vs Team objects, they could reference different cache entries if team.id != team.project_id

consider one of:

  1. always normalize integer keys to project_id via Team.objects.get(id=key).project_id
  2. update docstring to clarify callers must pass project_id integers, not team.id
Prompt To Fix With AI
This is a comment left during a code review.
Path: posthog/storage/hypercache.py
Line: 126:126

Comment:
**logic:** potential inconsistency: when an integer is passed as `key`, it's used directly in the cache key. but when a `Team` object is passed, `project_id` is used. if callers mix passing `team.id` (integer) vs `Team` objects, they could reference different cache entries if `team.id != team.project_id`

consider one of:
1. always normalize integer keys to project_id via `Team.objects.get(id=key).project_id`
2. update docstring to clarify callers must pass `project_id` integers, not `team.id`

How can I resolve this? If you propose a fix, please make it concise.

Copy link
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

This PR updates the flags hypercache to use project_id instead of team_id in cache keys, aligning the implementation with the semantic meaning of the cached data and future-proofing for when these IDs might differ.

  • Changed get_cache_key method to extract project_id from Team objects instead of id
  • Updated documentation comment to reflect that project_id is used as the cache key

Reviewed changes

Copilot reviewed 2 out of 2 changed files in this pull request and generated no comments.

File Description
posthog/storage/hypercache.py Modified get_cache_key to use team.project_id instead of team.id when a Team object is passed
posthog/models/feature_flag/flags_cache.py Updated documentation comment to clarify cache key uses project_id

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

@haacked haacked closed this Nov 24, 2025
@github-project-automation github-project-automation bot moved this from In Review to Done in Feature Flags Nov 24, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

Status: Done

Development

Successfully merging this pull request may close these issues.

2 participants