"simple" config settings and "complex" default values
(following discussion with @berruyer )
When using simple settings that match Redis types (like SimpleSetting
, HashSetting
for example), we
can give a default value that has a complexity beyond the Redis type. For example:
my_setting = HashSetting("toto", default_values={"a":{"tutu":5}, "b":3})
This creates a toto
hash in Redis - so far so good.
We can then do:
a_dict = my_setting["a"]
a_dict["tutu"] = 7
my_setting["a"] = a_dict # side note: this is also confusing, because the natural thing is to do
# my_setting["a"]["tutu"]=7` but this does not update the value in redis
# (but it is another, more difficult, "problem" ; maybe the easiest is
# just to not support __setitem__ and __getitem__ ?)
in order to update the value.
Except that this does not work as expected, because it is transformed into a string:
>>> my_setting
<HashSetting name=toto value={'a': "{'tutu': 7}", 'b': 3}>
This is because read_type_conversion
only understand scalars, and write_type_conversion
is str
.
A solution is to use HashObjSetting
for example => conversions are done with pickle
.
The question is:
- should we limit HashSetting and simple settings to only scalar values ?
- how to make user experience better ?