fix(): fixed bugs with cache invalidation, notifications and guardrails
This commit is contained in:
@@ -1,6 +1,7 @@
|
||||
from decimal import Decimal
|
||||
from typing import Any
|
||||
|
||||
from django.core.cache import cache
|
||||
from django.core.exceptions import ValidationError
|
||||
from django.db import transaction
|
||||
|
||||
@@ -305,6 +306,7 @@ def _transition(
|
||||
)
|
||||
experiment.status = new_status
|
||||
experiment.save(update_fields=["status", "updated_at"])
|
||||
cache.delete(f"active_exp:{experiment.flag_id}")
|
||||
ExperimentLog.objects.create(
|
||||
experiment=experiment,
|
||||
log_type=log_type,
|
||||
@@ -464,11 +466,13 @@ def experiment_resume(*, experiment: Experiment, user: User) -> Experiment:
|
||||
ensure_owner_or_admin(experiment, user)
|
||||
_validate_no_active_flag_conflict(experiment)
|
||||
validate_domain_conflicts(experiment)
|
||||
return _transition(
|
||||
experiment = _transition(
|
||||
experiment,
|
||||
ExperimentStatus.RUNNING,
|
||||
user,
|
||||
)
|
||||
_notify("experiment_resumed", experiment)
|
||||
return experiment
|
||||
|
||||
|
||||
@transaction.atomic
|
||||
|
||||
@@ -349,6 +349,26 @@ class RejectAndReqChangesTest(TestCase):
|
||||
exp = experiment_reopen(experiment=exp, user=self.experimenter)
|
||||
self.assertEqual(exp.status, ExperimentStatus.DRAFT)
|
||||
|
||||
def test_unauthorized_reject_raises(self) -> None:
|
||||
outsider = make_approver("_rr_out")
|
||||
with self.assertRaises(ValidationError) as ctx:
|
||||
experiment_reject(
|
||||
experiment=self.exp,
|
||||
user=outsider,
|
||||
comment="nope",
|
||||
)
|
||||
self.assertIn("user", ctx.exception.message_dict)
|
||||
|
||||
def test_unauthorized_request_changes_raises(self) -> None:
|
||||
outsider = make_approver("_rr_rc")
|
||||
with self.assertRaises(ValidationError) as ctx:
|
||||
experiment_request_changes(
|
||||
experiment=self.exp,
|
||||
user=outsider,
|
||||
comment="nope",
|
||||
)
|
||||
self.assertIn("user", ctx.exception.message_dict)
|
||||
|
||||
|
||||
class LifecycleFlowTest(TestCase):
|
||||
@override
|
||||
|
||||
Reference in New Issue
Block a user