mirror of https://github.com/zulip/zulip.git
do_set_realm_property: Noop if value isn't really changing.
It makes no sense to do operations if the value isn't changing. In particular, this creates RealmAuditLog entries and sends useless events.
This commit is contained in:
parent
cf68f8ae24
commit
b09f3a2da1
|
@ -56,6 +56,9 @@ def do_set_realm_property(
|
|||
), f"Cannot update {name}: {value} is not an instance of {property_type}"
|
||||
|
||||
old_value = getattr(realm, name)
|
||||
if old_value == value:
|
||||
return
|
||||
|
||||
setattr(realm, name, value)
|
||||
realm.save(update_fields=[name])
|
||||
|
||||
|
|
|
@ -3532,7 +3532,11 @@ class RealmPropertyActionTest(BaseAction):
|
|||
if vals is None:
|
||||
raise AssertionError(f"No test created for {name}")
|
||||
now = timezone_now()
|
||||
original_val = getattr(self.user_profile.realm, name)
|
||||
|
||||
do_set_realm_property(self.user_profile.realm, name, vals[0], acting_user=self.user_profile)
|
||||
|
||||
if vals[0] != original_val:
|
||||
self.assertEqual(
|
||||
RealmAuditLog.objects.filter(
|
||||
realm=self.user_profile.realm,
|
||||
|
|
Loading…
Reference in New Issue