test-fullautomation / python-jsonpreprocessor

A preprocessor for json files
Apache License 2.0
2 stars 2 forks source link

Self test issue: JPP_0265 #111

Closed HolQue closed 2 months ago

HolQue commented 10 months ago

JSON code:

{
   "param1" : "prefix",
   "param2" : [1,2,3],
   "param3" : {"${param1}_${param2}_suffix" : "value"}
}

The expression "${param1}_${param2}_suffix" is the name of a dictionary key. And this dictionary is the value of "param3".

Because of param2 is a parameter of type list, a substitution of ${param2} within this key name is not allowed.

The JsonPreprocessor returns the following exception:

'Key name or value is a mix of nested parameters and hard coded parts. 
           The entire expression {"${param1}_${param2}_suffix" must be enclosed in quotes'

This error message is misleading and makes no sense. The problem here is not a missing quote. It seems that the opened curly bracket in {"${param1}_${param2}_suffix" is interpreted as part of a value. But it's a JSON syntax element that indicates the beginning of a dictionary definition instead.

Expected is an error message telling that it's not allowed to replace parameters of composite data types within key names.

Reference:

https://github.com/test-fullautomation/python-jsonpreprocessor/issues/69#issuecomment-1589581903

and latest JsonPreprocessor test branch.

test-fullautomation commented 8 months ago

@namsonx : What is the status of this issue?

test-fullautomation commented 8 months ago

Hi @namsonx , what is the status of this ticket? Thank you, Thomas

namsonx commented 8 months ago

Hello Thomas,

This ticket was solved together with ticket #117 in the pull-request #151

Thank you, Son

HolQue commented 8 months ago

Like already mentioned above and in other issues also, the expectation is:

Expected is an error message telling that it's not allowed to replace parameters of composite data types within key names. Instead of this the error message is:

'Setting value 'value' for parameter 'prefix_[1, 2, 3]_suffix' is not permissible when substituting parameters of composite data types in dictionary key names!'! This is misleading. Because the main statement of this error message is: It's not permissible to set the value 'value'. But this is not the problem. The root cause of the problem is reduced to an incidental (... when substituting...). But this is the problem.

It makes also no sense to provide the invalid name (prefix_[1, 2, 3]_suffix). Because this name is based on something that is forbidden. No need to mention the outcome of something forbidden.

You should print the original expression ("${param1}_${param2}_suffix") that causes the problem and you should give a clear statement about the reason for the error.

HolQue commented 8 months ago

It should also be obvious that this can happen in two cases: dictionary key names and parameter names. The second case is still not handled.

The JSON code

   "param1" : [1,2,3],
   "param2-${param1}" : 123

causes

'Could not set variable 'param2-[1, 2, 3]' with value '123'! Reason: cannot assign to operator (<string>, line 1)'!

Same issue like above: It is not allowed to replace parameters of composite data types within parameter names.

And the reason "cannot assign to operator" completely makes no sense in this context.

See also:

https://github.com/test-fullautomation/python-jsonpreprocessor/issues/69#issuecomment-1589575019

See also:

https://github.com/test-fullautomation/python-jsonpreprocessor/issues/69#issuecomment-1708337615

HolQue commented 8 months ago

Further aspects:

[1]

Dictionary key names and parameter names have to be handled in code (and therefore in error messages also) separately.

The JSON code

"list"    : [1,2,3],
"${list}" : 123

causes:

'Setting value '123' for parameter '[1, 2, 3]' is not permissible when substituting parameters of composite data types in dictionary key names!

That's wrong: "dictionary key names". A dictionary is not involved. It's a simple parameter name, but not a dictionary key name.

[2]

"list"           : [1,2,3],
"prefix_${list}" : 123

causes:

Could not set variable 'prefix_[1, 2, 3]' with value '123'! Reason: name 'prefix_' is not defined

Error message is incomplete and wrong. Expected is: It is not allowed to replace parameters of composite data types within parameter names.

[3]

"list"           : [1,2,3],
"${list}_suffix" : 123

causes:

Setting value '123' for parameter '[1, 2, 3]_suffix' is not permissible when substituting parameters of composite data types in dictionary key names!

Outcome: There is a difference between error message [2] and [3], depending on if a prefix or a suffix is added to the parameter of not allowed composite data type. But this should not make a difference.

Expected is that the data type of dollar operator expressions is checked with highest priority.

namsonx commented 7 months ago

Hello Holger,

I created new commit 422921b4 on stabi branch The error message now is Exception: Could not substitute parameter '${param1}_${param2}_suffix' due to a composite data types in dictionary key names! The value of parameter '${param2}' is [1, 2, 3]

Thank you, Son

test-fullautomation commented 7 months ago

Hi Son,

unfortunately the grammar is not correct. Please use instead: Exception: Could not substitute parameter '${param1}_${param2}_suffix'! Composite data types are not allowed. The value of parameter '${param2}' is [1, 2, 3]

Thank you, Thomas

namsonx commented 7 months ago

Hello Thomas,

Thank you for your comment! I updated and pushed the change to stabi branch.

Thank you, Son

HolQue commented 4 months ago

Retest partly successful. Lot's of improvements.

But one issue left.

The code

"list"           : [1,2,3],
"${list}_suffix" : 123

causes

Found expression '${list}_suffix' with at least one parameter of composite data type ('${JPavoidDataType_list}' is of type ...

Something went wrong in the error message: ${JPavoidDataType_list}

This does not happen in case of the affected expression (${list}_suffix) represents a dictionary key instead of a single parameter.

HolQue commented 4 months ago

Still open.

namsonx commented 4 months ago

Hello Holger,

I pushed the commit 296c9482f86 to stabi branch to update the error message.

Thank you, Son

test-fullautomation commented 4 months ago

Hi Son, can this be closed? Thank you, Thomas

HolQue commented 4 months ago

Last issue part (https://github.com/test-fullautomation/python-jsonpreprocessor/issues/111#issuecomment-1884817369) also solved.

Issue can be closed.