Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Bug: Duration field not working with cbor #173

Open
2 tasks done
TudorAndrei-Pythia opened this issue Apr 2, 2025 · 3 comments
Open
2 tasks done

Bug: Duration field not working with cbor #173

TudorAndrei-Pythia opened this issue Apr 2, 2025 · 3 comments

Comments

@TudorAndrei-Pythia
Copy link
Contributor

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

[email protected]

Is there an existing issue for this?

  • I have searched the existing issues

Code of Conduct

  • I agree to follow this project's Code of Conduct
@TudorAndrei-Pythia TudorAndrei-Pythia added the bug Something isn't working label Apr 2, 2025
@linear linear bot added Python SDK /surrealdb.py GitHub Bug and removed bug Something isn't working labels Apr 2, 2025
@maxwellflitton
Copy link
Contributor

Hey thanks for posting this. We have recently taken the cbor lib under our own hands so we have more control over it. You an see the process we took here. I'm looking into this issue and running it through a debugger to see how this can be solved.

@maxwellflitton
Copy link
Contributor

Hey @TudorAndrei-Pythia I have now done this pull request. It has the following test case which I hope provides you with the functionality you need.

@turbokadi
Copy link

@maxwellflitton Any news ?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

3 participants