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: flatten "base" in AssignmentEvent #46

Merged
merged 3 commits into from
Oct 16, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
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
1 change: 1 addition & 0 deletions eppo_core/src/events.rs
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,7 @@ pub struct AssignmentEventBase {
#[derive(Debug, Clone, Serialize)]
#[serde(rename_all = "camelCase")]
pub struct AssignmentEvent {
#[serde(flatten)]
Copy link
Collaborator Author

Choose a reason for hiding this comment

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

"flatten" unpacks a nested structure into parent when serializing

pub base: Arc<AssignmentEventBase>,
/// The key identifying the subject receiving the assignment.
pub subject: Str,
Expand Down
2 changes: 1 addition & 1 deletion python-sdk/Cargo.toml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
[package]
name = "eppo_py"
version = "4.0.2"
version = "4.0.3"
edition = "2021"
publish = false

Expand Down
22 changes: 22 additions & 0 deletions python-sdk/tests/test_assignment_logger.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,8 @@

from eppo_client.assignment_logger import AssignmentLogger

from .util import init


def test_can_inherit_assignment_logger():
class MyAssignmentLogger(AssignmentLogger):
Expand All @@ -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": "[email protected]"}, "default"
)
assert result == "partial-example"

assert event["allocation"] == "partial-example"
Copy link
Member

Choose a reason for hiding this comment

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

Does this demonstrate that nested elements, like base are no longer present?

Copy link
Collaborator Author

@rasendubi rasendubi Oct 16, 2024

Choose a reason for hiding this comment

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

yes. the test fails without the flatten tag

assert event["featureFlag"] == "regex-flag"
assert event["experiment"] == "regex-flag-partial-example"
assert event["metaData"]["sdkName"] == "python"
4 changes: 2 additions & 2 deletions python-sdk/tests/util.py
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand Down
4 changes: 2 additions & 2 deletions rust-sdk/Cargo.toml
Original file line number Diff line number Diff line change
@@ -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"
Expand All @@ -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"

Expand Down
Loading