style(): reformatted files
This commit is contained in:
@@ -201,9 +201,7 @@ def _decision_payload(result: dict, subject_id: str) -> dict:
|
||||
"subject_id": subject_id,
|
||||
"experiment_id": result.get("experiment_id"),
|
||||
"variant_id": result.get("variant_id"),
|
||||
"value": str(result["value"])
|
||||
if result["value"] is not None
|
||||
else "",
|
||||
"value": str(result["value"]) if result["value"] is not None else "",
|
||||
"reason": result["reason"],
|
||||
}
|
||||
|
||||
|
||||
@@ -469,11 +469,12 @@ class DecisionPersistenceModeTest(TestCase):
|
||||
|
||||
@override_settings(DECISION_WRITE_MODE="async")
|
||||
def test_async_mode_enqueues_non_assigned_result(self) -> None:
|
||||
with patch(
|
||||
with (
|
||||
patch(
|
||||
"apps.decision.services.persist_decision_task.delay"
|
||||
) as delay_mock, patch(
|
||||
"apps.decision.services.decision_create"
|
||||
) as create_mock:
|
||||
) as delay_mock,
|
||||
patch("apps.decision.services.decision_create") as create_mock,
|
||||
):
|
||||
result = decide_for_flag(self.flag.key, "subj_async", {})
|
||||
self.assertEqual(result["reason"], "no_active_experiment")
|
||||
delay_mock.assert_called_once()
|
||||
@@ -482,11 +483,12 @@ class DecisionPersistenceModeTest(TestCase):
|
||||
@override_settings(DECISION_WRITE_MODE="async")
|
||||
def test_async_mode_keeps_assigned_result_sync(self) -> None:
|
||||
self._make_running_experiment()
|
||||
with patch(
|
||||
with (
|
||||
patch(
|
||||
"apps.decision.services.persist_decision_task.delay"
|
||||
) as delay_mock, patch(
|
||||
"apps.decision.services.decision_create"
|
||||
) as create_mock:
|
||||
) as delay_mock,
|
||||
patch("apps.decision.services.decision_create") as create_mock,
|
||||
):
|
||||
result = decide_for_flag(
|
||||
self.flag.key,
|
||||
"subj_async_assigned",
|
||||
|
||||
@@ -30,8 +30,7 @@ from apps.metrics.models import (
|
||||
class PercentileCont(Aggregate):
|
||||
function = "PERCENTILE_CONT"
|
||||
template = (
|
||||
"%(function)s(%(percentile)s) "
|
||||
"WITHIN GROUP (ORDER BY %(expressions)s)"
|
||||
"%(function)s(%(percentile)s) WITHIN GROUP (ORDER BY %(expressions)s)"
|
||||
)
|
||||
allow_distinct = False
|
||||
output_field = FloatField()
|
||||
@@ -92,9 +91,7 @@ def _numeric_property_expression(property_field: str):
|
||||
pattern = r"^-?(?:\d+(?:\.\d+)?|\.\d+)$"
|
||||
return Case(
|
||||
When(
|
||||
**{
|
||||
f"properties__{property_field}__regex": pattern
|
||||
},
|
||||
**{f"properties__{property_field}__regex": pattern},
|
||||
then=Cast(key_text, FloatField()),
|
||||
),
|
||||
default=Value(None),
|
||||
@@ -150,14 +147,18 @@ def _percentile_property(
|
||||
start_date: datetime | None = None,
|
||||
end_date: datetime | None = None,
|
||||
) -> Decimal | None:
|
||||
qs = _events_queryset(
|
||||
qs = (
|
||||
_events_queryset(
|
||||
exposure_qs=exposure_qs,
|
||||
event_type_name=event_type_name,
|
||||
start_date=start_date,
|
||||
end_date=end_date,
|
||||
).annotate(
|
||||
)
|
||||
.annotate(
|
||||
numeric_value=_numeric_property_expression(property_field),
|
||||
).exclude(numeric_value__isnull=True)
|
||||
)
|
||||
.exclude(numeric_value__isnull=True)
|
||||
)
|
||||
if connection.vendor == "postgresql":
|
||||
value = qs.aggregate(
|
||||
value=PercentileCont(
|
||||
|
||||
Reference in New Issue
Block a user