question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

UnSecureDataError when reading JSON value

See original GitHub issue

Affects version: 3.3.0

I have the following key defining a stringified JSON as value stored in Redis:

$ redis-cli -h localhost -p 16379
localhost:16379> get packing:product_scan_220000000111
"{\"shipping_information_id\": 1, \"scanned_product\": {\"id\": 43, \"barcode\": \"220000000111\", \"dimensions\": [334, 36]}, \"added_products\": [], \"packing_auto\": true}"
localhost:16379> 

Using this code:

from cashews import cache

...
cache.setup(f"redis://{cfg.redis.host}:{cfg.redis.port}/0",
            password=redis_password,
            prefix="packing")

result = await cache.get("packing:product_scan_220000000111")

I get an UnSecureDataError:

Traceback (most recent call last):
  File "/home/automation/lib/python3.7/site-packages/aiorun.py", line 212, in new_coro
    await coro
  File "/home/automation/packing/application.py", line 136, in main
    ":product_scan_220000000111")
  File "/home/automation/packing/application.py", line 39, in cache_logging_middleware
    return await call(*args, **kwargs)
  File "/home/automation/lib/python3.7/site-packages/cashews/validation.py", line 63, in _invalidate_middleware
    return await call(*args, key=key, **kwargs)
  File "/home/automation/lib/python3.7/site-packages/cashews/wrapper.py", line 50, in _auto_init
    return await call(*args, **kwargs)
  File "/home/automation/lib/python3.7/site-packages/cashews/disable_control.py", line 12, in _is_disable_middleware
    return await call(*args, **kwargs)
  File "/home/automation/lib/python3.7/site-packages/cashews/serialize.py", line 35, in get
    return await self._get_value(await super().get(key), key, default=default)
  File "/home/automation/lib/python3.7/site-packages/cashews/serialize.py", line 39, in _get_value
    return self._process_value(value, key, default=default)
  File "/home/automation/lib/python3.7/site-packages/cashews/serialize.py", line 59, in _process_value
    raise UnSecureDataError()
cashews.serialize.UnSecureDataError

It the serializer parses the value and splits it on ‘_’ for some check, but I completely miss the background for this.

Is this expected? How can I read this value properly in cashews?

Issue Analytics

  • State:closed
  • Created 2 years ago
  • Comments:9 (1 by maintainers)

github_iconTop GitHub Comments

1reaction
rkrellcommented, Mar 10, 2022

Oh, great, haven’t even noticed that possibility 😃 The community may forgive you the breaking change 😉

0reactions
Krukovcommented, Mar 9, 2022

@rkrell

With a shame I can say that it is possible to get value without any serialization. I did very silly mistake with naming (english is not native for me, I don’t know how it can happened) - set_row , get_row. It should be raw of course

await cache.get_row("test")

So I going to fix this naming without backward compatibility ( for versions 4.x.x)

Read more comments on GitHub >

github_iconTop Results From Across the Web

What Is JSON and How to Handle an “Unexpected Token” Error
The first thing to do in this situation is to confirm where the error is happening exactly. To ensure the error happens on...
Read more >
Error when posting data with cURL - json - Stack Overflow
Your data in -d doesn't seem to be in json format. Try jsonlint to validate json format. Or if you are trying to...
Read more >
What is a JSON Injection and How to Prevent it? - Comparitech
We explain everything you need to know about JSON Injection attack, including how it works, and how to detect and prevent it.
Read more >
SyntaxError: JSON.parse: bad parsing - JavaScript | MDN
JSON.parse() parses a string as JSON. This string has to be valid JSON and will throw this error if incorrect syntax was encountered....
Read more >
How to debug "Error while reading data, error message ...
Ensure JSON is valid , search on google or click on the url: “json online viewer” · you may have an invalid JSON...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found