Skip to content

Empty subject attributes in python are empty tuples instead of None #211

Closed
@bennettandrews

Description

@bennettandrews

We ran into an issue where we were dropping assignment events in our downstream logger due to unexpected subject attribute values. If a None value is passed into subject attributes, they come back as empty tuple in the AssignmentLogger such as user_id: () which does not conform to the expected type of subject_attributes: Dict[str, Union[str, int, float, bool, None]],.

We ended up adding:

return {
  k: None if v == () else v|
  for k, v in assignment_event.get("subjectAttributes", {}).items()
}

The issue seems to be in https://github.com/Eppo-exp/eppo-multiplatform/blob/main/eppo_core/src/pyo3.rs#L28. The rust Option<T> when None is converted back to python uses ().to_object(py) which will create an empty tuple object instead of py.None()

Example

Tested on eppo-sever-sdk 4.0.0 and 4.2.4

client = eppo_client.get_instance()
user = get_current_user()

variation = client.get_boolean_assignment(
    'show-new-feature',
    user.id,
    { 'country': None },
    False
)

With AssignmentLogger

class LocalAssignmentLogger(AssignmentLogger):
	def log_assignment(self, assignment_event: dict) -> None:
		subject_attributes = assignment_event.get("subjectAttributes", {})
		print(f"Subject attributes: {subject_attributes}")

Country comes back as ()

Subject attributes: {'country': () } 

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions