Skip to content
This repository was archived by the owner on Oct 9, 2023. It is now read-only.
This repository was archived by the owner on Oct 9, 2023. It is now read-only.

Python client datetimes are influenced by time zone #298

Closed
@steenstral

Description

@steenstral

Description

The Python client API is inconsistent with time zones. When a datetime attribute is inserted, everything is fine. However, when this same attribute is queried, there is an offset of 2 hours (UTC+01:00 + summertime).

Environment

  1. OS: Windows 10
  2. TypeDB version: TypeDB 2.17.0
  3. TypeDB client-python version: client-python 2.17.0 (the newest release 2.18.0 crashes at this moment for some reason)
  4. Python version: Python 3.10.6, Python 3.8.2 and Python 3.7.8 (tested the issue on these three versions)
  5. Other environment details: Clean venv with only typedb-client installed

Reproducible Steps

  1. Make sure that the system time is NOT on (UTC+00:00) or summer/wintertime is ENABLED
  2. Create a virtual environment and install the client
python3 -m venv venv               # Create virtual environment in Python 3
.\venv\Scripts\activate            # Activate the virtual environment
pip install typedb-client==2.17.0  # Install the typedb-client (version 2.18.0 crashes)
  1. Run the TypeDB server
typedb server  # Version 2.17.0
  1. Run this minimal test python file
from typedb.client import TypeDB, SessionType, TransactionType


KEYSPACE = "datetime_issue"


def main() -> None:
    # Create a client
    with TypeDB.core_client(TypeDB.DEFAULT_ADDRESS) as client:
        # Create the keyspace if it does not exist
        if not client.databases().contains(KEYSPACE):
            client.databases().create(KEYSPACE)

        # Create a schema session
        with client.session(KEYSPACE, SessionType.SCHEMA) as session:
            with session.transaction(TransactionType.WRITE) as write_schema_transaction:
                # Only define a datetime attribute
                query = "define test_date sub attribute, value datetime;"
                write_schema_transaction.query().define(query)
                write_schema_transaction.commit()

        # Create a data session
        with client.session(KEYSPACE, SessionType.DATA) as session:
            with session.transaction(TransactionType.WRITE) as write_data_transaction:
                # Insert first of every month, at 00:00:00
                query = """insert
                $time_date_jan isa test_date;  $time_date_jan 2023-01-01T00:00:00;
                $time_date_feb isa test_date;  $time_date_feb 2023-02-01T00:00:00;
                $time_date_mar isa test_date;  $time_date_mar 2023-03-01T00:00:00;
                $time_date_apr isa test_date;  $time_date_apr 2023-04-01T00:00:00;
                $time_date_may isa test_date;  $time_date_may 2023-05-01T00:00:00;
                $time_date_jun isa test_date;  $time_date_jun 2023-06-01T00:00:00;
                $time_date_jul isa test_date;  $time_date_jul 2023-07-01T00:00:00;
                $time_date_aug isa test_date;  $time_date_aug 2023-08-01T00:00:00;
                $time_date_sep isa test_date;  $time_date_sep 2023-09-01T00:00:00;
                $time_date_oct isa test_date;  $time_date_oct 2023-10-01T00:00:00;
                $time_date_nov isa test_date;  $time_date_nov 2023-11-01T00:00:00;
                $time_date_dec isa test_date;  $time_date_dec 2023-12-01T00:00:00;
                """
                write_data_transaction.query().insert(query)
                write_data_transaction.commit()

            with session.transaction(TransactionType.READ) as read_data_transaction:
                # Match all date attributes and print them
                query = "match $date isa test_date; get $date;"
                answer = read_data_transaction.query().match(query)  # <- PROBLEM IS HERE
                dates = [ans.get("date") for ans in answer]
                for date in dates:
                    print(f"Retrieved date: {date.get_value()}")


if __name__ == "__main__":
    main()

Expected Output

I would expect to retrieve back the exact same dates as inserted in the query().insert():

Retrieved date: 2023-01-01 00:00:00
Retrieved date: 2023-02-01 00:00:00
Retrieved date: 2023-03-01 00:00:00
Retrieved date: 2023-04-01 00:00:00
Retrieved date: 2023-05-01 00:00:00
Retrieved date: 2023-06-01 00:00:00
Retrieved date: 2023-07-01 00:00:00
Retrieved date: 2023-08-01 00:00:00
Retrieved date: 2023-09-01 00:00:00
Retrieved date: 2023-10-01 00:00:00
Retrieved date: 2023-11-01 00:00:00
Retrieved date: 2023-12-01 00:00:00

Actual Output

Instead, there is a clear offset in time, 1 hour in wintertime and 2 hours in summertime (exactly UTC+01:00).

Retrieved date: 2023-01-01 01:00:00
Retrieved date: 2023-02-01 01:00:00
Retrieved date: 2023-03-01 01:00:00
Retrieved date: 2023-04-01 02:00:00
Retrieved date: 2023-05-01 02:00:00
Retrieved date: 2023-06-01 02:00:00
Retrieved date: 2023-07-01 02:00:00
Retrieved date: 2023-08-01 02:00:00
Retrieved date: 2023-09-01 02:00:00
Retrieved date: 2023-10-01 02:00:00
Retrieved date: 2023-11-01 01:00:00
Retrieved date: 2023-12-01 01:00:00

Additional information

  • Issue is in the Python client (TypeDB Studio works fine)
    Doing a read data match query in the datetime_issue keyspace inside of TypeDB Studio 2.11.0 on Windows, does NOT have this time offset. This means that the problem is clearly in the Python API, especially in the transaction.query().match(query) method.
  • It depends on the system time
    When the system time in Windows is changed to UTC+00:00 and summer-/wintertime is disabled, there is no time offset.

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions