Skip to content

Commit

Permalink
schema1: set the new plan_ids keys (#1467)
Browse files Browse the repository at this point in the history
Amplitude cannot do a filter that match a single key in an array, if we want to
correctly identify an event's plan(s) we need to flatten the plan_id keys.
  • Loading branch information
goneri authored Jan 8, 2025
1 parent 7db0b08 commit 18994c7
Show file tree
Hide file tree
Showing 2 changed files with 3 additions and 0 deletions.
2 changes: 2 additions & 0 deletions ansible_ai_connect/ai/api/telemetry/schema1.py
Original file line number Diff line number Diff line change
Expand Up @@ -96,6 +96,7 @@ class Schema1Event:
_user: User | None = None
_created_at: int = time.time()
plans: list[PlanEntry] = Factory(list)
plan_ids: list[int] = Factory(list)
timestamp: str | None = None
duration: float | None = None

Expand All @@ -119,6 +120,7 @@ def set_user(self, user):
self.rh_user_org_id = user.organization.id
self.groups = list(user.groups.values_list("name", flat=True))
self.plans = [PlanEntry.init(up) for up in user.userplan_set.all()]
self.plan_ids = [up.plan_id for up in user.userplan_set.all()]

def set_request(self, request):
if hasattr(request, "user"): # e.g WSGIRequest generated when we run update-openapi-schema
Expand Down
1 change: 1 addition & 0 deletions ansible_ai_connect/ai/api/telemetry/test_schema1.py
Original file line number Diff line number Diff line change
Expand Up @@ -98,6 +98,7 @@ def test_new_trial_record_plan(self):
self.assertEqual(event1.plans[0].name, "Some plan")
self.assertTrue(event1.plans[0].created_at.startswith("20"))
self.assertEqual(event1.plans[0].plan_id, self.trial_plan.id)
self.assertEqual(event1.plan_ids, [self.trial_plan.id])


@override_settings(AUTHZ_BACKEND_TYPE="dummy")
Expand Down

0 comments on commit 18994c7

Please sign in to comment.