Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat(feature flags): copy cohorts linked to a flag #18642

Merged
merged 68 commits into from
Nov 17, 2023

Conversation

jurajmajerik
Copy link
Contributor

@jurajmajerik jurajmajerik commented Nov 15, 2023

Problem

When copying a feature flag to another project, the copying fails if the linked cohort doesn't exist in the target project.

Changes

Before copying, create any missing cohorts in the destination project.

To check if the cohort exists in the destination project, we search for the first cohort that matches by name. While it's possible there could be multiple cohorts with the same name, the user should resolve these duplications manually anyway (perhaps worth showing a warning prompt in the UI).

I went through the trouble of sorting linked cohorts by their creation order (post-order DFS), only to realize that the current implementation already returns ids in their creation order. This is because cohort ids are auto-incrementing, and converting the cohort_ids set into a list sorts them in the ascending order, which is, in fact, the order we want.

However, I'm unsure if this is something to be relied upon - perhaps there's an edge case I haven't thought of yet. That said, the current tests pass even when sort_by_creation_order is set to False.

How did you test this code?

API test, 👀

jurajmajerik and others added 30 commits November 13, 2023 12:04
Copy link
Contributor

github-actions bot commented Nov 16, 2023

Size Change: 0 B

Total Size: 2.01 MB

ℹ️ View Unchanged
Filename Size
frontend/dist/toolbar.js 2.01 MB

compressed-size-action

@posthog-bot
Copy link
Contributor

📸 UI snapshots have been updated

1 snapshot changes in total. 0 added, 1 modified, 0 deleted:

  • chromium: 0 added, 1 modified, 0 deleted (diff for shard 2)
  • webkit: 0 added, 0 modified, 0 deleted

Triggered by this commit.

👉 Review this PR's diff of snapshots.

Copy link
Collaborator

@neilkakkar neilkakkar left a comment

Choose a reason for hiding this comment

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

Almost there, good tests, good job!

Can we move the seen_cohort_cache type change to a separate PR though, it's becoming a bit too big and this one's risky on its own, since it changes high volume endpoints

posthog/api/test/test_feature_flag_utils.py Show resolved Hide resolved
posthog/api/test/test_organization_feature_flag.py Outdated Show resolved Hide resolved
posthog/api/test/test_organization_feature_flag.py Outdated Show resolved Hide resolved
posthog/models/cohort/util.py Outdated Show resolved Hide resolved
@jurajmajerik jurajmajerik merged commit 93e2011 into master Nov 17, 2023
70 checks passed
@jurajmajerik jurajmajerik deleted the multi-project-feature-flags branch November 17, 2023 11:43
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants