h2non / jsonpath-ng

Finally, a JSONPath implementation for Python that aims to be standard compliant. That's all. Enjoy!
Apache License 2.0
564 stars 85 forks source link

expression.update() returns none #163

Open 3mrrrx opened 5 months ago

3mrrrx commented 5 months ago

this might be a bug!

the following in example working in version 1.6.0 but returns None in version 1.6.1

jsonpath_expression = parse(  "$..UPPERCASE") 

def lowercase_value(orig,data,field):
    data[field] = data[field].lower()

dict_x = {
    "Data_cat": {
        "data_entry": [
            {"value": 0, "UPPERCASE": "UPPERCASE_A"},
            {"value": 2, "UPPERCASE": "UPPERCASE_B"},
        ]
    }
}
jsonpath_expression.update(dict_x, lowercase_value)

return in 1.6.0

dict_x = {
    "Data_cat": {
        "data_entry": [
            {"value": 0, "UPPERCASE": "uppercase_a"},
            {"value": 2, "UPPERCASE": "uppercase_b"},
        ]
    }
}

return in 1.6.1

dict_x = {
    "Data_cat": {
        "data_entry": [
            {"value": 0, "UPPERCASE": None},
            {"value": 2, "UPPERCASE": None},
        ]
    }
}
michaelmior commented 5 months ago

Thanks for flagging this! It looks like it was introduced in 7987969ef85e92b700f947f3e61b5f8ce2421187.

michaelmior commented 5 months ago

It looks like this is arguably not a bug, but certainly a change in behavior. Lambdas were changed to use the return value as the new value of the field. So the update function in your example above could be rewritten as

def lowercase_value(orig,data,field):
    return data[field].lower()
jmkolbe commented 4 months ago

Hi, thanks for looking into this and your explanation and your work on this valuable project in general. For what it's worth, a change in behavior is not necessarily expected in a patch release. If this change is to stay, some migration documentation would be appreciated.