From a5df3d728663a38726cf2bd7946a45aaca69ee73 Mon Sep 17 00:00:00 2001 From: bohan-amplitude Date: Wed, 22 Jun 2022 15:19:31 -0700 Subject: [PATCH 1/3] fix set_group Put group_type and group_name in groups attributes of IdentifyEvent instead of user_properties. --- src/amplitude/client.py | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/src/amplitude/client.py b/src/amplitude/client.py index ac0ccbf..5c197a8 100644 --- a/src/amplitude/client.py +++ b/src/amplitude/client.py @@ -4,7 +4,7 @@ Amplitude: the Amplitude client class """ -from typing import Optional, Union, List +from typing import Optional, Union, List, Final from amplitude.config import Config from amplitude.event import Revenue, BaseEvent, Identify, IdentifyEvent, GroupIdentifyEvent, EventOptions @@ -43,7 +43,7 @@ def __init__(self, api_key: str, configuration: Config = Config()): configuration (amplitude.config.Config, optional): The configuration of client instance. A new instance with default config value will be used by default. """ - self.configuration: Config = configuration + self.configuration: Final[Config] = configuration self.configuration.api_key = api_key self.__timeline = Timeline() self.__timeline.setup(self) @@ -125,9 +125,9 @@ def set_group(self, group_type: str, group_name: Union[str, List[str]], event_op event_options (amplitude.event.EventOptions): Provide additional information for event like user_id. """ - identify_obj = Identify() - identify_obj.set(group_type, group_name) - self.identify(identify_obj, event_options) + event = IdentifyEvent(groups={group_type: group_name}) + event.load_event_options(event_options) + self.track(event) def flush(self): """Flush all event waiting to be sent in the buffer""" From 26913077caac549250015f8f470810e30bc85749 Mon Sep 17 00:00:00 2001 From: bohan-amplitude Date: Wed, 22 Jun 2022 15:22:39 -0700 Subject: [PATCH 2/3] remove Final supported in 3.8 --- src/amplitude/client.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/amplitude/client.py b/src/amplitude/client.py index 5c197a8..291d99f 100644 --- a/src/amplitude/client.py +++ b/src/amplitude/client.py @@ -4,7 +4,7 @@ Amplitude: the Amplitude client class """ -from typing import Optional, Union, List, Final +from typing import Optional, Union, List from amplitude.config import Config from amplitude.event import Revenue, BaseEvent, Identify, IdentifyEvent, GroupIdentifyEvent, EventOptions @@ -43,7 +43,7 @@ def __init__(self, api_key: str, configuration: Config = Config()): configuration (amplitude.config.Config, optional): The configuration of client instance. A new instance with default config value will be used by default. """ - self.configuration: Final[Config] = configuration + self.configuration: Config = configuration self.configuration.api_key = api_key self.__timeline = Timeline() self.__timeline.setup(self) From c9ff55339df312d87f6b9c3c6b55a773641cefce Mon Sep 17 00:00:00 2001 From: bohan-amplitude Date: Wed, 22 Jun 2022 15:24:50 -0700 Subject: [PATCH 3/3] update set group test case --- src/test/test_client.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/test/test_client.py b/src/test/test_client.py index 83b6042..3c29d04 100644 --- a/src/test/test_client.py +++ b/src/test/test_client.py @@ -174,11 +174,11 @@ def test_amplitude_set_group_success(self): def callback_func(event, code, message=None): self.assertEqual(200, code) self.assertTrue(isinstance(event, IdentifyEvent)) - self.assertTrue("user_properties" in event) + self.assertTrue("groups" in event) self.assertEqual("$identify", event["event_type"]) self.assertEqual("test_user_id", event["user_id"]) self.assertEqual("test_device_id", event["device_id"]) - self.assertEqual({"$set": {"type": ["test_group", "test_group_2"]}}, event.user_properties) + self.assertEqual({"type": ["test_group", "test_group_2"]}, event.groups) self.client.configuration.callback = callback_func for use_batch in (True, False):