h2non/jsonpath-ng

expression.update() returns none

3mrrrx opened this issue · 3 comments

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},
        ]
    }
}

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

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()

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.