Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[bug/admin] Device configuration variables not updating when templates defines same variable #781

Open
pandafy opened this issue Jun 28, 2023 · 0 comments

Comments

@pandafy
Copy link
Member

pandafy commented Jun 28, 2023

Consider the following scenario, where there are two templates as follows:

  1. Template: "Access Points"
    • Configuration Variable: {'ssid': 'OpenWISP'}
  2. Template: "Wireless Radio"
    • Configuration Variable: {'ssid': 'placeholder'}

How to replicate

  1. Create a device object
  2. Select the "Wireless Radio" template on a device. The configuration variables are populated, and you see {'ssid': 'placeholder'}. This is correct.
  3. Now, select the "Access Points" template. Ensure that it comes after the "Wireless Radio" template.

Expected Result:
You would expect the configuration variables to reflect {'ssid': 'OpenWISP'} because the new template has a different value for ssid.

Actual Result:
The configuration variables still show {'ssid': 'placeholder'}.

Explanation:
The issue occurs due to this JavaScript code:

Object.keys(defaultValues).forEach(function (key) {
if (!contextValue.hasOwnProperty(key) && !systemContextValue.hasOwnProperty(key)) {
contextValue[key] = defaultValues[key];
}
});

The code only updates the configuration variables if the key is not defined in the System Defined Variables and is not already defined in the Configuration Variables for the device.

In this case, when you change the template, the configuration variables already have {'ssid': 'placeholder'} because it was set by the previous template. Therefore, the code does not update the configuration variable, assuming the user intentionally set it and wants to preserve their custom value.

This behavior was likely implemented to prevent overriding of configuration variables that were intentionally set by the user.

Originally posted by @pandafy in #779 (comment)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Development

No branches or pull requests

1 participant