redis-py icon indicating copy to clipboard operation
redis-py copied to clipboard

Colons ':' acting as special characters when used in path while doing json().set

Open ajavia opened this issue 3 years ago • 3 comments

Version: redis-py 4.1.4, redis 6.2.7

Platform: Python 3.10.5 on MacOS 12.6.1

Description:

I am trying to set a key-value pair inside an existing key (of type json).

For example: redis_client.json().set(f'user:{user_id}', path, value) where path = "foo:bar" and value = true. user:user_id already exists and has data.

The result is that the document gets updated successfully with a new key-value pair called "foo": true instead of "foo:bar": true. This does not happen when I execute a set with path = '$' and the whole document with the "foo:bar" : true key-value pair.

I tried escaping with 'foo\:bar' but that did not work.

Please advise.

Thank you!

ajavia avatar Nov 30 '22 20:11 ajavia

Hi @ajavia I don't think you're triggering what you're hoping for. Your path, has to be a valid jsonpath syntax. Can you share your code sample?

I tried reproducing this with a dictionary containing the following data paths

x = {"hello:f": "my am", "we": "are", "th:ey": "say hi!"}

Then, I tried a few path based sets:

r.json().set('user:1', '.' ...)
r.json().set('user:1', '$' ...)
r.json().set('user:1', '$.th:ey' ...)
r.json().set('user:1', '$..th:ey' ...)   <--- this one clearly raises an exception

Mind sharing a sample?

chayim avatar Mar 06 '23 10:03 chayim

Hi @chayim, I unfortunately no longer have access to that specific code, as the logic is no longer required and the repo has been pruned.

But, I can scrounge up an example with the data I am using.

Existing key user:user_id:

{
    "userName": "[email protected]",
    "id": "user_id",
    "foo:bar": {
        "department": "department",
        "employeeNumber": "00000000"
    }
}

Note that the issue I faced was without the '$' in the path i.e. "foo:bar" instead of "$.foo:bar". So if that is the expected behavior, then this issue can be considered closed.

Sorry for not being able to assist with a detailed sample.

ajavia avatar Mar 06 '23 17:03 ajavia

This issue is marked stale. It will be closed in 30 days if it is not updated.

github-actions[bot] avatar Mar 06 '24 00:03 github-actions[bot]