Skip to content
This repository was archived by the owner on Nov 21, 2026. It is now read-only.
This repository was archived by the owner on Nov 21, 2026. It is now read-only.

Database.lookup_by_key raises 'Unable to convert' for a datetime or date key that the same value bound to a SQL parameter finds #123

Closed

Description

@tae898

Level: bindings. db.lookup_by_key(type_name, keys, values) on a unique index over a DATETIME or DATE property fails with ArcadeDBError: Failed to lookup by key in 'Meeting': Unable to convert when the key is a Python datetime or date, although the record exists and SELECT ... WHERE at = ? with the same value finds it. The error does not say what could not be converted.

Repro

The script prints to stdout. The JVM's own log lines go to stderr and are discarded by the command below.

uv venv .venv
uv pip install --python .venv/bin/python arcadedb_embedded-26.10.1.dev0-cp312-cp312-manylinux_2_34_x86_64.whl
.venv/bin/python repro-18-lookup-by-key-datetime.py 2>/dev/null
"""lookup_by_key raises 'Unable to convert' for a datetime or date key; the same value bound to a SQL parameter finds the record."""
import datetime as dt
import os
import tempfile

import arcadedb_embedded as arcade
from arcadedb_embedded.jvm import start_jvm

start_jvm(heap_size="2g")
db = arcade.create_database(os.path.join(tempfile.mkdtemp(prefix="hb18-"), "db"))
for type_name, prop_type in (("Meeting", "DATETIME"), ("Holiday", "DATE")):
    db.command("sql", f"CREATE DOCUMENT TYPE {type_name}")
    db.command("sql", f"CREATE PROPERTY {type_name}.at {prop_type}")
    db.command("sql", f"CREATE INDEX ON {type_name} (at) UNIQUE")
when = dt.datetime(2024, 5, 6, 7, 8, 9)
day = dt.date(2024, 5, 6)
with db.transaction():
    db.command("sql", "INSERT INTO Meeting SET at = ?, title = 'standup'", when)
    db.command("sql", "INSERT INTO Holiday SET at = ?, title = 'spring day'", day)

for type_name, key in (("Meeting", when), ("Holiday", day)):
    sql_hit = db.query("sql", f"SELECT title FROM {type_name} WHERE at = ?", key).first()
    print(f"{type_name} / {key!r}")
    print("   SQL  WHERE at = ?  ->", sql_hit.get("title") if sql_hit else None)
    try:
        hit = db.lookup_by_key(type_name, ["at"], [key])
        print("   db.lookup_by_key   ->", hit.get("title") if hit else None)
    except Exception as e:
        print(f"   db.lookup_by_key   -> {type(e).__name__}: {e}")
db.close()

Output

Wheel arcadedb_embedded-26.10.1.dev0-cp312-cp312-manylinux_2_34_x86_64.whl with its bundled JRE (OpenJDK 25.0.4.1), JPype 1.7.1, and Python 3.12.13. The engine build the wheel reports through com.arcadedb.Constants is 26.10.1-SNAPSHOT (build 04bb03ebec07fce19101595d65ca1e3bdf516755), an ancestor of upstream cecb369df9. The repository is at f92ac1381c8335249a6fde644cbf04594f6d6391, and the installed Python sources are identical to bindings/python/src/arcadedb_embedded/ at that commit.

Meeting / datetime.datetime(2024, 5, 6, 7, 8, 9)
   SQL  WHERE at = ?  -> standup
   db.lookup_by_key   -> ArcadeDBError: Failed to lookup by key in 'Meeting': Unable to convert
Holiday / datetime.date(2024, 5, 6)
   SQL  WHERE at = ?  -> spring day
   db.lookup_by_key   -> ArcadeDBError: Failed to lookup by key in 'Holiday': Unable to convert

Cause

lookup_by_key builds the key array with jpype.JArray(jpype.JObject)(values) (core.py L403) and does not pass the values through convert_python_to_java, which every other entry point uses for datetime, date, Decimal, bytes, and collections (core.py L98-L104). The message Unable to convert carries no detail, and I did not trace which layer raises it.

Expected

A datetime or date key finds the record, as it does as a SQL parameter.

Proposed fix

Convert each value before building the array:

--- a/bindings/python/src/arcadedb_embedded/core.py
+++ b/bindings/python/src/arcadedb_embedded/core.py
-            values_array = jpype.JArray(jpype.JObject)(values)
+            values_array = jpype.JArray(jpype.JObject)([convert_python_to_java(v) for v in values])

A run-time monkeypatch of the same conversion makes both lookups in the repro return their record.

Related issues

Nothing found upstream. Issue #58 (closed) made Decimal, date, and datetime work as SQL parameters and did not reach this method.

In this repository's tracker no issue is about this. The search for lookup_by_key found nothing.

Related reports from the same review: #127 (Instant conversion).

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

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions