mirror of
https://github.com/zulip/zulip.git
synced 2025-11-22 07:21:23 +00:00
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:
committed by
Tim Abbott
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}"
|
), f"Cannot update {name}: {value} is not an instance of {property_type}"
|
||||||
|
|
||||||
old_value = getattr(realm, name)
|
old_value = getattr(realm, name)
|
||||||
|
if old_value == value:
|
||||||
|
return
|
||||||
|
|
||||||
setattr(realm, name, value)
|
setattr(realm, name, value)
|
||||||
realm.save(update_fields=[name])
|
realm.save(update_fields=[name])
|
||||||
|
|
||||||
|
|||||||
@@ -3532,7 +3532,11 @@ class RealmPropertyActionTest(BaseAction):
|
|||||||
if vals is None:
|
if vals is None:
|
||||||
raise AssertionError(f"No test created for {name}")
|
raise AssertionError(f"No test created for {name}")
|
||||||
now = timezone_now()
|
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)
|
do_set_realm_property(self.user_profile.realm, name, vals[0], acting_user=self.user_profile)
|
||||||
|
|
||||||
|
if vals[0] != original_val:
|
||||||
self.assertEqual(
|
self.assertEqual(
|
||||||
RealmAuditLog.objects.filter(
|
RealmAuditLog.objects.filter(
|
||||||
realm=self.user_profile.realm,
|
realm=self.user_profile.realm,
|
||||||
|
|||||||
Reference in New Issue
Block a user