Fix an issue in user settings
* UserSettings: crashed if overwrite an existing key with primitive value by same key with complex value. Also reduced number of calls to user.get_setting() * Updated tests (cherry picked from commit b75b53d)
This commit is contained in:
parent
a0e5f79483
commit
8a4934e6f8
3 changed files with 8 additions and 6 deletions
|
|
@ -77,6 +77,7 @@ date of first contribution):
|
|||
* [Noah Martin](https://github.com/noahsmartin)
|
||||
* [Eyal Soha](https://github.com/eyal0)
|
||||
* [Greg Hulands](https://github.com/ghulands)
|
||||
* [Andreas Werner](https://github.com/gallore)
|
||||
|
||||
OctoPrint started off as a fork of [Cura](https://github.com/daid/Cura) by
|
||||
[Daid Braam](https://github.com/daid). Parts of its communication layer and
|
||||
|
|
|
|||
|
|
@ -314,9 +314,8 @@ class FilebasedUserManager(UserManager):
|
|||
raise UnknownUser(username)
|
||||
|
||||
user = self._users[username]
|
||||
current = user.get_setting(key)
|
||||
if not current or current != value:
|
||||
old_value = user.get_setting(key)
|
||||
old_value = user.get_setting(key)
|
||||
if not old_value or old_value != value:
|
||||
user.set_setting(key, value)
|
||||
self._dirty = self._dirty or old_value != value
|
||||
self._save()
|
||||
|
|
@ -482,7 +481,7 @@ class User(UserMixin):
|
|||
def _get_setting(self, path):
|
||||
s = self._settings
|
||||
for p in path:
|
||||
if p in s:
|
||||
if isinstance(s, dict) and p in s:
|
||||
s = s[p]
|
||||
else:
|
||||
return None
|
||||
|
|
@ -495,7 +494,7 @@ class User(UserMixin):
|
|||
s[p] = dict()
|
||||
|
||||
if not isinstance(s[p], dict):
|
||||
return False
|
||||
s[p] = dict()
|
||||
|
||||
s = s[p]
|
||||
|
||||
|
|
|
|||
|
|
@ -63,7 +63,9 @@ class UserTestCase(unittest.TestCase):
|
|||
(["sub", "othersubkey"], "othersubvalue", dict(sub=dict(othersubkey="othersubvalue")), True),
|
||||
("booleankey", True, dict(booleankey=True), True),
|
||||
(["newsub", "newsubkey"], "newsubvalue", dict(newsub=dict(newsubkey="newsubvalue")), True),
|
||||
(["sub", "subkey", "wontwork"], "wontwork", dict(), False)
|
||||
# ["sub", "subkey"] is already existing and gets overwritten
|
||||
(["sub", "subkey", "subsubkey"], "42", dict(sub=dict(subkey=dict(subsubkey="42"))), True),
|
||||
(["sub"], "overwrite", dict(sub="overwrite"), True)
|
||||
)
|
||||
@ddt.unpack
|
||||
def test_set_setting_string(self, key, value, update, expected_returnvalue):
|
||||
|
|
|
|||
Loading…
Reference in a new issue