surrealdb.py
surrealdb.py copied to clipboard
Bug: Duration field not working with cbor
Describe the bug
I have this field
DEFINE FIELD rate_limit_reset ON TABLE api_keys TYPE duration
DEFAULT 1h;
File "/home//api/src/api/TESTSTST.py", line 19, in main
result = await db.query(
^^^^^^^^^^^^^^^
File "/home//api/.venv/lib/python3.12/site-packages/surrealdb/connections/async_ws.py", line 135, in query
response = await self._send(message, "query")
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
File "/home//api/.venv/lib/python3.12/site-packages/surrealdb/connections/async_ws.py", line 61, in _send
response = decode(await self.socket.recv())
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
File "/home/radu/Repos/cleardata/api/.venv/lib/python3.12/site-packages/surrealdb/data/cbor.py", line 143, in decode
return cbor2.loads(data, tag_hook=tag_decoder)
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
File "/home//api/.venv/lib/python3.12/site-packages/surrealdb/data/cbor.py", line 122, in tag_decoder
return Duration.parse(tag.value[0], tag.value[1]) # Two numbers (s, ns)
~~~~~~~~~^^^
IndexError: list index out of range
but it works if I add the comments in surrealdb/data/cbor.py", line 122, in tag_decoder
elif tag.tag == constants.TAG_DURATION_COMPACT:
# if len(tag.value) == 1:
# return Duration.parse(0, tag.value[0])
return Duration.parse(tag.value[0], tag.value[1]) # Two numbers (s, ns)
Steps to reproduce
see above
Expected behaviour
no errors
SurrealDB version
surreal 2.2.1 linux amd64
surrealdb.py version
surrealdb.py 1.0.3 on linux with Python 3.12.8
Contact Details
Is there an existing issue for this?
- [x] I have searched the existing issues
Code of Conduct
- [x] I agree to follow this project's Code of Conduct