gqlalchemy icon indicating copy to clipboard operation
gqlalchemy copied to clipboard

Error using datetime

Open alexanderseik opened this issue 3 years ago • 1 comments

Hi,

I am new to this lib and I played around with timestamps in my graph.

When I run my example below I get the following error:

gqlalchemy\connection.py", line 92, in execute_and_fetch
    cursor.execute(query)
mgclient.DatabaseError: Function 'datetime.datetime' doesn't exist.

I tested it with gqlalchemy 1.3.1.

Example:

from datetime import datetime
from gqlalchemy import Memgraph, Node, Relationship, Field

class User(Node):
    id: str = Field(index=True, unique=True, db=db)
    name: str = Field()
    timestamp: datetime = Field()

User(id="1", name="myUser", timestamp=datetime.now()).save(db)

After running into this error I did a little bit of debugging. I printed the underlying cypher statement:

MATCH (node: User) WHERE  node.id = '1'  RETURN node;
CREATE (node:User)   SET node.id = '1'  SET node.name = 'myUser'  SET node.timestamp = datetime.datetime(2022, 7, 24, 0, 32, 51, 583238)  RETURN node;

Here one can see 'datetime.datetime(2022, 7, 24, 0, 32, 51, 583238)'. This seems to be the datetime object representation instead of 'localDateTime(...)'. See: https://github.com/memgraph/gqlalchemy/blob/8324c2fb6ef41771ad39c75bd3620fc4fec0f212/tests/test_utilities.py#L69 I also found out that 'to_cypher_value(...)' is never called in my case.

If I switch the type to 'str' instead of 'datetime' I do not get any error.

Btw., nice lib :-)!

BR, Alexander

alexanderseik avatar Jul 23 '22 22:07 alexanderseik

Hi @alexanderseik, thank you for reporting this. I will check this out and get back to you 😄 Also, thanks for the nice words for the GQLAlchemy 😊

katarinasupe avatar Jul 25 '22 07:07 katarinasupe