From a2786aff4a66bc4daf176b2b4375fe462b7db237 Mon Sep 17 00:00:00 2001 From: Oleksii Shmalko Date: Wed, 16 Oct 2024 20:29:46 +0300 Subject: [PATCH] fix: flatten "base" in AssignmentEvent (#46) * fix: flatten "base" in event * chore: bump versions --- eppo_core/src/events.rs | 1 + python-sdk/Cargo.toml | 2 +- python-sdk/tests/test_assignment_logger.py | 22 ++++++++++++++++++++++ python-sdk/tests/util.py | 4 ++-- rust-sdk/Cargo.toml | 4 ++-- 5 files changed, 28 insertions(+), 5 deletions(-) diff --git a/eppo_core/src/events.rs b/eppo_core/src/events.rs index b8fcbafb..804f0bb6 100644 --- a/eppo_core/src/events.rs +++ b/eppo_core/src/events.rs @@ -38,6 +38,7 @@ pub struct AssignmentEventBase { #[derive(Debug, Clone, Serialize)] #[serde(rename_all = "camelCase")] pub struct AssignmentEvent { + #[serde(flatten)] pub base: Arc, /// The key identifying the subject receiving the assignment. pub subject: Str, diff --git a/python-sdk/Cargo.toml b/python-sdk/Cargo.toml index d8e4a46f..e3713684 100644 --- a/python-sdk/Cargo.toml +++ b/python-sdk/Cargo.toml @@ -1,6 +1,6 @@ [package] name = "eppo_py" -version = "4.0.2" +version = "4.0.3" edition = "2021" publish = false diff --git a/python-sdk/tests/test_assignment_logger.py b/python-sdk/tests/test_assignment_logger.py index eb4bcd0d..bccc498a 100644 --- a/python-sdk/tests/test_assignment_logger.py +++ b/python-sdk/tests/test_assignment_logger.py @@ -2,6 +2,8 @@ from eppo_client.assignment_logger import AssignmentLogger +from .util import init + def test_can_inherit_assignment_logger(): class MyAssignmentLogger(AssignmentLogger): @@ -27,3 +29,23 @@ def test_has_log_assignment(): def test_has_log_bandit_action(): AssignmentLogger().log_bandit_action({}) + + +def test_event_format(): + event = None + + class MyAssignmentLogger(AssignmentLogger): + def log_assignment(self, assignment_event: Dict): + nonlocal event + event = assignment_event + + client = init("ufc", assignment_logger=MyAssignmentLogger()) + result = client.get_string_assignment( + "regex-flag", "alice", {"email": "alice@example.com"}, "default" + ) + assert result == "partial-example" + + assert event["allocation"] == "partial-example" + assert event["featureFlag"] == "regex-flag" + assert event["experiment"] == "regex-flag-partial-example" + assert event["metaData"]["sdkName"] == "python" diff --git a/python-sdk/tests/util.py b/python-sdk/tests/util.py index 6191d3ef..e32b4d10 100644 --- a/python-sdk/tests/util.py +++ b/python-sdk/tests/util.py @@ -6,12 +6,12 @@ from eppo_client.config import Config, AssignmentLogger -def init(suite, *, wait_for_init=True): +def init(suite, *, wait_for_init=True, assignment_logger=AssignmentLogger()): client = eppo_client.init( Config( api_key="blah", base_url=f"http://localhost:8378/{suite}/api", - assignment_logger=AssignmentLogger(), + assignment_logger=assignment_logger, ) ) if wait_for_init: diff --git a/rust-sdk/Cargo.toml b/rust-sdk/Cargo.toml index dfc7a3ad..606f634a 100644 --- a/rust-sdk/Cargo.toml +++ b/rust-sdk/Cargo.toml @@ -1,6 +1,6 @@ [package] name = "eppo" -version = "4.0.0" +version = "4.0.1" edition = "2021" description = "Eppo SDK for Rust" homepage = "https://docs.geteppo.com/sdks/server-sdks/rust" @@ -11,7 +11,7 @@ categories = ["config"] rust-version = "1.71.1" [dependencies] -eppo_core = { version = "4.1.0", path = "../eppo_core" } +eppo_core = { version = "=4.1.0", path = "../eppo_core" } log = { version = "0.4.21", features = ["kv", "kv_serde"] } serde_json = "1.0.116"