Skip to content
Open
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
8 changes: 7 additions & 1 deletion python/lib/sift_client/_internal/low_level_wrappers/rules.py
Original file line number Diff line number Diff line change
Expand Up @@ -124,10 +124,10 @@ def _update_rule_request_from_create(self, create: RuleCreate) -> UpdateRuleRequ
update_request = UpdateRuleRequest(
name=create.name,
description=create.description,
is_enabled=True,
organization_id=create.organization_id or "",
client_key=create.client_key,
is_external=create.is_external,
is_live_evaluation_enabled=create.evaluate_on_live_data,
conditions=conditions_request,
asset_configuration=RuleAssetConfiguration(
asset_ids=create.asset_ids or [],
Expand Down Expand Up @@ -207,6 +207,7 @@ def _update_rule_request_from_update(
"contextual_channels",
"asset_ids",
"asset_tag_ids",
"evaluate_on_live_data",
]
# Need to manually copy fields that will be reset even if not provided in update dict.
copy_unset_fields = ["description", "name"]
Expand Down Expand Up @@ -262,6 +263,11 @@ def _update_rule_request_from_update(
channels=[ChannelReferenceProto(name=c) for c in update.contextual_channels or []]
)

# Map is_live (class field) to is_live_evaluation_enabled (proto field)
update_dict["is_live_evaluation_enabled"] = model_dump.get(
"evaluate_on_live_data", rule.evaluate_on_live_data
)

# This always needs to be set, so handle the defaults.
update_dict["asset_configuration"] = RuleAssetConfiguration( # type: ignore
asset_ids=(update.asset_ids if "asset_ids" in model_dump else rule.asset_ids or []),
Expand Down
1 change: 0 additions & 1 deletion python/lib/sift_client/_tests/resources/test_rules.py
Original file line number Diff line number Diff line change
Expand Up @@ -335,7 +335,6 @@ async def test_update_rule_description(self, rules_api_async, new_rule):
assert updated_rule.description == "Updated description"
# Validate that things we didn't intentionally change didn't change
assert updated_rule.name == new_rule.name
assert updated_rule.is_enabled == new_rule.is_enabled
assert updated_rule.is_external == new_rule.is_external
assert updated_rule.expression == new_rule.expression
assert updated_rule.action.action_type == new_rule.action.action_type
Expand Down
3 changes: 2 additions & 1 deletion python/lib/sift_client/_tests/sift_types/test_rule.py
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,6 @@ def mock_rule(mock_client):
id_="test_rule_id",
name="test_rule",
description="test description",
is_enabled=True,
created_date=datetime.now(timezone.utc),
modified_date=datetime.now(timezone.utc),
created_by_user_id="user1",
Expand All @@ -46,6 +45,8 @@ def mock_rule(mock_client):
client_key=None,
rule_version=None,
archived_date=None,
evaluate_on_live_data=False,
current_version_id="test_version_id",
)
rule._apply_client_to_instance(mock_client)
return rule
Expand Down
7 changes: 5 additions & 2 deletions python/lib/sift_client/sift_types/rule.py
Original file line number Diff line number Diff line change
Expand Up @@ -45,14 +45,15 @@ class Rule(BaseType[RuleProto, "Rule"]):
# Required fields
name: str
description: str
is_enabled: bool
created_date: datetime
modified_date: datetime
created_by_user_id: str
modified_by_user_id: str
organization_id: str
is_archived: bool
is_external: bool
evaluate_on_live_data: bool
current_version_id: str

# Optional fields
expression: str | None
Expand Down Expand Up @@ -135,7 +136,6 @@ def _from_proto(cls, proto: RuleProto, sift_client: SiftClient | None = None) ->
].expression.calculated_channel.channel_references.items()
],
action=RuleAction._from_proto(proto.conditions[0].actions[0]),
is_enabled=proto.is_enabled,
created_date=proto.created_date.ToDatetime(tzinfo=timezone.utc),
modified_date=proto.modified_date.ToDatetime(tzinfo=timezone.utc),
created_by_user_id=proto.created_by_user_id,
Expand All @@ -153,6 +153,8 @@ def _from_proto(cls, proto: RuleProto, sift_client: SiftClient | None = None) ->
),
is_archived=proto.is_archived,
is_external=proto.is_external,
evaluate_on_live_data=proto.is_live_evaluation_enabled,
current_version_id=proto.current_version_id,
_client=sift_client,
)

Expand All @@ -166,6 +168,7 @@ class RuleCreateUpdateBase(ModelCreateUpdateBase):
asset_tag_ids: list[str] | None = None
contextual_channels: list[str] | None = None
is_external: bool = False
evaluate_on_live_data: bool = False


class RuleCreate(RuleCreateUpdateBase, ModelCreate[CreateRuleRequest]):
Expand Down
Loading