Skip to content

Commit 282500e

Browse files
[fix] Avoid mutating device.name in _get_common_name #<issue-number>
1 parent 762ae3c commit 282500e

File tree

1 file changed

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

1 file changed

+4
-3
lines changed

openwisp_controller/config/base/vpn.py

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -892,12 +892,13 @@ 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+
data = {**d.__dict__, "name": name}
901+
common_name = cn_format.format(**data)[:55]
901902
common_name = f"{common_name}-{unique_slug}"
902903
return common_name
903904

0 commit comments

Comments
 (0)