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

fix(batch-exports): Include properties in feature_enabled call #17860

Merged
merged 4 commits into from
Oct 9, 2023
Merged
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
19 changes: 14 additions & 5 deletions posthog/batch_exports/http.py
Original file line number Diff line number Diff line change
Expand Up @@ -170,11 +170,20 @@ def create(self, validated_data: dict) -> BatchExport:
destination_data = validated_data.pop("destination")
team_id = self.context["team_id"]

if validated_data["interval"] not in ("hour", "day", "week") and not posthoganalytics.feature_enabled(
"high-frequency-batch-exports",
Copy link
Collaborator

Choose a reason for hiding this comment

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

hey @tomasfarias you can try this locally to check if it works or not. (just create the same feature flag in your local env with the same match by and check if it works)

In this case, the feature flag is based on the project group, and not distinct IDs, which means you need to pass in the groups parameter with key project and value as the project ID.

So, you just need to add project instead of organization in this case, and the property 'id' in group_properties

Copy link
Collaborator

Choose a reason for hiding this comment

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

One potential gotcha, and reason not to use project and use organisations instead is that currently this will enable it for both, team 2 and 9291 in EU and US both, vs. just those teams in US.

Hence, using org IDs, which are unique across deployments works better usually.

Copy link
Contributor Author

@tomasfarias tomasfarias Oct 9, 2023

Choose a reason for hiding this comment

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

We can switch the flag to organizations. That means the code changes implemented here are enough, right? Thank you for your input!

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I've tested things out locally using this branch and flags based on organization and things work 👍 (Discovered a frontend bug while I was at it).

str(Team.objects.get(id=team_id).uuid),
):
raise PermissionDenied("Higher frequency exports are not enabled for this team.")
if validated_data["interval"] not in ("hour", "day", "week"):
team = Team.objects.get(id=team_id)

if not posthoganalytics.feature_enabled(
"high-frequency-batch-exports",
str(team.uuid),
groups={"organization": str(team.organization.id)},
group_properties={
"organization": {"id": str(team.organization.id), "created_at": team.organization.created_at}
},
only_evaluate_locally=True,
send_feature_flag_events=False,
):
raise PermissionDenied("Higher frequency exports are not enabled for this team.")

destination = BatchExportDestination(**destination_data)
batch_export = BatchExport(team_id=team_id, destination=destination, **validated_data)
Expand Down
Loading