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: #110

Open
2 tasks done
yghaderi opened this issue Sep 6, 2024 · 3 comments
Open
2 tasks done

Bug: #110

yghaderi opened this issue Sep 6, 2024 · 3 comments
Labels
bug Something isn't working

Comments

@yghaderi
Copy link

yghaderi commented Sep 6, 2024

Describe the bug

insert datetime value to table

Steps to reproduce

I want insert this {'date': '2023-07-03T07:18:52.841147', 'open': 27430.0, 'high': 27730.0, 'low': 27420.0, 'close': 27720.0, 'final': 27490.0, 'y_final': 27190.0, 'vol': 713407.0, 'val': 19755901740.0, 'count': 560.0, 'ins': 'instrument:IRO1ABIK0001'} record to databse but resive this error surrealdb.ws.SurrealPermissionException: There was a problem with the database: Found '2023-07-03T07:18:52.841147' for field date, with record trade:mb5zls5xah1xyo4rsa1o, but expected a datetime. how can fixed it?

Expected behaviour

insert record.

SurrealDB version

2.0.0 beta linux

surrealdb.py version

0.3.2

Contact Details

No response

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
@exius-netrunner
Copy link

exius-netrunner commented Dec 12, 2024

Not sure what the status is on this bug, but I've noticed that this issue is still ongoing as of SurrealDB v2.1.3 and SDK v0.4.1

Attempting to insert datetime as a data type is returning an exception:

Code [connection_address is ws://<ip_address>:8000]:

from datetime import datetime, timezone
from surrealdb import SurrealDB
import auth


def connection():
    db = SurrealDB(url=auth.connection_address)
    db.connect()
    db.use(auth.test_ns, auth.test_db)
    db.sign_in(auth.db_username, auth.db_password)

    db.upsert("prices", {
        "timestamp": datetime.now(timezone.utc)
    })
    return db

Result:

('no decoder for tag', 12)
Event loop stopped before Future completed.

I've tried through upserting, inserting, and through a custom query for both which always ends up as the same result.
Likewise switching between context / async / both modes hasn't done anything to resolve it either.

Clearly the issue is still open, so presuming that this is still known.

Modifying it this way does seem to resolve the bug:

datetime.now(timezone.utc).isoformat()

However, the formatting in SurrealDB does not reflect a standard d'timestamp here' and does not auto convert to a human readable format in Surrealist as it would without .isoformat().

Additionally, it looks closer to a string value when in .isoformat() so I can't tell if it's getting read as datetime or as a string value for sure once it's placed in the database. It is however classified in python as a datetime value when appended with .isoformat().

Edit: After further evaluation in Surrealist, this is likely just a string still, so can't really say that it resolved this way.

.isoformat():
timestamp: '2024-12-12T11:56:16.006686+00:00'

@lfnovo
Copy link

lfnovo commented Dec 24, 2024

Same issue here.. SurrealDB expects us to send dates as d'2023-07-17T07:18:52Z' but there is no practical way to do that in Python and there seems to be no helper function in the SDK for that either. What's the right way to use datetime with the Python SDK, guys?

@lfnovo
Copy link

lfnovo commented Dec 24, 2024

I ended up building a simple Pydantic ORM implementation for Surreal which I plan to add to later. Feel free to contribute if you guys like the idea.

https://pypi.org/project/surrantic/

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

No branches or pull requests

3 participants