Skip to content

Commit 46acb5f

Browse files
committed
[fix] Avoid mutating device.name in _get_common_name #1300
This fixes an issue where device.name was modified in-place, which could cause unexpected behavior due to Django ORM caching. Fixes #1300
1 parent 45b24b6 commit 46acb5f

File tree

1 file changed

+3
-3
lines changed
  • openwisp_controller/config/base

1 file changed

+3
-3
lines changed

openwisp_controller/config/base/vpn.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -892,12 +892,12 @@ def _get_common_name(self):
892892
"""
893893
d = self.config.device
894894
end = 63 - len(d.mac_address)
895-
d.name = d.name[:end]
895+
name = d.name[:end]
896896
unique_slug = shortuuid.ShortUUID().random(length=8)
897897
cn_format = app_settings.COMMON_NAME_FORMAT
898-
if cn_format == "{mac_address}-{name}" and d.name == d.mac_address:
898+
if cn_format == "{mac_address}-{name}" and name == d.mac_address:
899899
cn_format = "{mac_address}"
900-
common_name = cn_format.format(**d.__dict__)[:55]
900+
common_name = cn_format.format(**{**d.__dict__, "name": name})[:55]
901901
common_name = f"{common_name}-{unique_slug}"
902902
return common_name
903903

0 commit comments

Comments
 (0)