Skip to content

Commit f1de100

Browse files
committed
Temporary disable implicit creation of data structure based on nested params
1 parent 8435da7 commit f1de100

File tree

1 file changed

+20
-11
lines changed

1 file changed

+20
-11
lines changed

JsonPreprocessor/CJsonPreprocessor.py

Lines changed: 20 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -497,31 +497,35 @@ def __handleDotdictFormat(self, lInputListParams : list, lParams: list = []) ->
497497
else:
498498
return self.__handleDotdictFormat(lInputListParams, lParams)
499499

500-
def __checkAndCreateNewElement(self, sKey: str, value):
500+
def __checkAndCreateNewElement(self, sKey: str, value, bCheck=False):
501501
'''
502502
This method check and create new elements if they are not exist.
503503
'''
504504
rootKey = re.sub("\[.*\]", "", sKey)
505505
subElements = re.findall("\[\s*'([0-9A-Za-z_]+[0-9A-Za-z\.\-_]*)'\s*\]", sKey)
506-
if len(subElements) <= 1:
507-
return
506+
if len(subElements) < 1:
507+
return True
508508
else:
509509
for index, element in enumerate(subElements):
510-
if index < len(subElements) - 1:
510+
if index < len(subElements):
511511
rootKey = rootKey + "['" + element + "']"
512512
sExec = "dumpData = " + rootKey
513513
try:
514514
exec(sExec)
515515
except:
516-
sExec = rootKey + " = {}"
517-
try:
518-
exec(sExec, globals())
519-
except Exception as error:
520-
self.__reset()
521-
errorMsg = f"Could not set variable '{sKey}' with value '{value}'! Reason: {error}"
522-
raise Exception(errorMsg)
516+
if bCheck==True:
517+
return False # Return 'False' when detected implicit creation of data structures based on nested parameters.
518+
else:
519+
sExec = rootKey + " = {}"
520+
try:
521+
exec(sExec, globals())
522+
except Exception as error:
523+
self.__reset()
524+
errorMsg = f"Could not set variable '{sKey}' with value '{value}'! Reason: {error}"
525+
raise Exception(errorMsg)
523526
else:
524527
continue
528+
return True
525529

526530
def __updateAndReplaceNestedParam(self, oJson : dict, bNested : bool = False, recursive : bool = False):
527531
'''
@@ -669,6 +673,11 @@ def __loadNestedValue(initValue: str, sInputStr: str, bKey=False, key=''):
669673
keyAfterProcessed = self.__nestedParamHandler(k, bKey=True)
670674
k = re.sub("\$\$", "$", k)
671675
k = re.sub('^\s*\${\s*(.*?)\s*}', '\\1', keyAfterProcessed[0])
676+
if re.search("\[\s*'" + pattern + "'\s*\]", keyNested): # Temporary disable implicit creation of data structures based on nested parameters.
677+
if not self.__checkAndCreateNewElement(k, v, bCheck=True): # In case check sub-element returns False -> reset() and raise an exception.
678+
self.__reset()
679+
raise Exception(f"\nThe implicit creation of data structures based on nested parameter does not enable yet.\n\
680+
New parameter '{k}' could not be created by the expression '{keyNested}'")
672681
elif k.count('{') != k.count('}'):
673682
self.__reset()
674683
raise Exception(f"Could not overwrite parameter {k} due to wrong format.\n \

0 commit comments

Comments
 (0)