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

Parameter not resolved or not handled properly at lower levels #215

Open
HolQue opened this issue Feb 2, 2024 · 2 comments
Open

Parameter not resolved or not handled properly at lower levels #215

HolQue opened this issue Feb 2, 2024 · 2 comments

Comments

@HolQue
Copy link
Collaborator

HolQue commented Feb 2, 2024

The following code contains nested dictionaries and lists:

"params" : {"A" : 1,
            "B" : ["C", {"D" : 2,
                         "E" : ["F", 3]
                        }
                  ]
}

Based on this pattern I replace step by step single elements by a parameter.

(1)

"param1" : "X",
"params" : {"A" : 1,
            "${param1}" : ["C", {"D" : 2,
                                 "E" : ["F", 3]}]
}

Result:

{'param1': 'X', 'params': {'A': 1, 'X': ['C', {'D': 2, 'E': ['F', 3]}]}}

OK so far. But the key 'X' is a key created by a parameter. Do we want to allow this here?

(2)

"param1" : "X",
"params" : {"A" : 1,
            "B" : ["C", {"${param1}" : 2,
                                 "E" : ["F", 3]}]
}

Result:

{'param1': 'X',
 'params': {'A': 1, 'B': ['C', {'E': ['F', 3], 'str(${param1})': 2}]}}

Parsing went wrong.

(3)

"param1" : "X",
"params" : {"A" : 1,
            "B" : ["C", {"D" : ${param1},
                         "E" : ["F", 3]}]
}

Result:

{'param1': 'X',
 'params': {'A': 1, 'B': ['C', {'D': '${param1}', 'E': ['F', 3]}]}}

Parsing went wrong.

(4)

"param1" : "X",
"params" : {"A" : 1,
            "B" : ["C", {"D" : "${param1}",
                         "E" : ["F", 3]}]
}

Result:

{'param1': 'X',
 'params': {'A': 1,
            'B': ['C',
                  {'D': '${param1}__ConvertParameterToString__',
                   'E': ['F', 3]}]}}

String conversion failed

(5)

"param1" : "X",
"params" : {"A" : 1,
            "B" : ["C", {"D" : 2,
                         "${param1}" : ["F", 3]}]
}

Result:

{'param1': 'X',
 'params': {'A': 1,
            'B': ['C',
                  {'${param1}__ConvertParameterToString__': ['F', 3], 'D': 2}]}}

Interesting: In (2) "D" has been replaced by the dollar operator expression, instead of "E". And the error message is different. Here it's the second key in the dictionary. In (2) it's the first key. Position dependency?

(6)

"param1" : "X",
"params" : {"A" : 1,
            "B" : ["C", {"D" : 2,
                         "E" : [${param1}, 3]}]
}

Result:

{'param1': 'X', 'params': {'A': 1, 'B': ['C', {'D': 2, 'E': ['${param1}', 3]}]}}

Parsing went wrong.

(7)

"param1" : "X",
"params" : {"A" : 1,
            "B" : ["C", {"D" : 2,
                         "E" : ["${param1}", 3]}]
}

Result:

{'param1': 'X',
 'params': {'A': 1,
            'B': ['C',
                  {'D': 2, 'E': ['${param1}__ConvertParameterToString__', 3]}]}}

String conversion failed

(8)

"param1" : "X",
"params" : {"A" : 1,
            "B" : ["C", {"D" : 2,
                         "E" : ["F", ${param1}]}]
}

Result:

Error: 'Invalid nested parameter format: ${param1}]}] - The double quotes are missing!!!'!

Why this? There are no quotes missing.

(9)

"param1" : "X",
"params" : {"A" : 1,
            "B" : ["C", {"D" : 2,
                         "E" : ["F", "${param1}"]}]
}

Result:

{'param1': 'X',
 'params': {'A': 1, 'B': ['C', {'D': 2, 'E': ['F', 'str(${param1})']}]}}

Parsing went wrong.

(10)

Extended substitution:

"param1" : "X",
"param2" : {"G" : 5, "H" : 6},
"param3" : ["G", "H"],
"params" : {"A" : 1,
            "B" : ["C", {"D" : "ABC ${param2}[${param3}[0]] DEF",
                         "E" : ["F", 3]}]
}

Result:

Error: 'The variable '${param3}[0]]' is not available!'!

JsonPreprocessor is not able to handle the two successive ']]' in '${param2}[${param3}[0]]'.

(11)

With additional single quotes, to avoid ']]' and to force the explicit string conversion:

"param1" : "X",
"param2" : {"G" : 5, "H" : 6},
"param3" : ["G", "H"],
"params" : {"A" : 1,
            "B" : ["C", {"D" : "ABC ${param2}['${param3}[0]'] DEF",
                         "E" : ["F", 3]}]
}

Result:

Error: 'list index out of range'!

Why is that? There is no list index out of range.

(12)

In dotdict notation:

"param1" : "X",
"param2" : {"G" : 5, "H" : 6, "X" : 9},
"param3" : ["G", "H"],
"params" : {"A" : 1,
            "B" : ["C", {"D" : 2,
                         "E" : [1, "ABC ${param2.${param1}} DEF", 3]
                        }
                  ]
}

Result:

{'param1': 'X',
 'param2': {'G': 5, 'H': 6, 'X': 9},
 'params': {'A': 1,
            'B': ['C',
                  {'D': 2,
                   'E': [1, 'ABC str(${param2.str(${param1})}) DEF', 3]}]}}

Parsing went wrong.

@namsonx
Copy link
Collaborator

namsonx commented May 28, 2024

Hello Holger,

For the cases (1), (2), and (5), these cases will raised the exception Exception: A substitution in key names is not allowed!... based on requirement #270

For other cases you mentioned in this ticket, I already implemented and all cases are working as expected. Could you please help me verify them on stabi branch.

Thank you,
Son

@HolQue
Copy link
Collaborator Author

HolQue commented May 31, 2024

Retest successful. Issue can be closed.

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

No branches or pull requests

3 participants