Skip to content

Commit 3155b0d

Browse files
authored
1 parent e2abc8f commit 3155b0d

File tree

1 file changed

+14
-3
lines changed

1 file changed

+14
-3
lines changed

cid/helpers/parameter_store.py

Lines changed: 14 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
import json
12
import logging
23
from datetime import datetime
34

@@ -34,7 +35,16 @@ def load(self):
3435
def _to_sql_str(self, val):
3536
if val is None:
3637
return "''"
37-
return "'" + str(val).replace("'", "''") + "'"
38+
return "'" + str(json.dumps(val)).replace("'", "''") + "'"
39+
40+
def _from_sql_str(self, string):
41+
if string.endswith(']') and string.startswith('[') and string.count("'") >=2:
42+
# this is an old style parameters so transform it to json readable form from __repr__
43+
string = string.replace("'",'"')
44+
try:
45+
return json.loads(string)
46+
except json.JSONDecodeError:
47+
return string
3848

3949
def _generate_view_query(self, data, name):
4050
all_keys = {key for dictionary in data for key in dictionary.keys()}
@@ -56,9 +66,10 @@ def load_parameters(self, context):
5666
any_parameters = {}
5767
# get any context and then override with specific context
5868
for line in sorted(data, key=lambda x: x.get('date', '')): # latest should override
59-
any_parameters[line.get('parameter')] = line.get('value')
69+
val = self._from_sql_str(line.get('value'))
70+
any_parameters[line.get('parameter')] = val
6071
if line.get('context') == str(context):
61-
context_parameters[line.get('parameter')] = line.get('value')
72+
context_parameters[line.get('parameter')] = val
6273
return any_parameters | context_parameters
6374

6475
def dump_parameters(self, params, context=None):

0 commit comments

Comments
 (0)