Hacktoberfest 2026: the issues maintainers tagged for October, open and beginner-friendly. Browse Hacktoberfest issues

QueryIndexAsync rejects a DateTime bound

Open Beginner friendly
#270 0 comments 0 reactions 0 assignees View on GitHub

Maintainers usually reply within 1 day

Nobody has claimed this yet.

Assessment

Difficulty
2/5
Estimated time
1-3 hours
Newbie friendliness
75/100
Issue type
Bug
Clarity
Clearly specified
Activity status
Active
Tech stack
csharp
Domain
database

Research direction

Start with CreateIndexKeyFromObject in src/BLite.Core/DynamicCollection.cs and compare its supported bound types with BsonValueToIndexKey and CompareFilter.ToIndexObject, which the issue identifies as the working date conversion paths. Check how the BSON writer handles an unspecified DateTime, then run the DynamicCollection oracle cases in tests/BLite.Tests/Oracles/DynamicDifferentialTests.cs. Done means DateTime and DateTimeOffset bounds return the expected date range results.

Written by the indexing model from the issue text.

Description

area/indexing bug package/core triage

DynamicCollection.QueryIndexAsync throws ArgumentException: Cannot create IndexKey from type DateTime for a DateTime (or DateTimeOffset) bound, although the index keys DateTime values and the README shows a date range through it. BLQL on the same index works, because it converts its bounds itself.

Found by the DynamicCollection oracle tests (tests/BLite.Tests/Oracles/DynamicDifferentialTests.cs, PR to follow, stacked on #263), which carry the affected rows (16: indexed/api, both oracles, e.g. when < t5, when >= t10 and < t20, Count(when < t5)) as a known candidate until this is fixed.

Repro

await col.CreateIndexAsync("when");   // m0, m5, m10: t0 plus 0, 5, 10 minutes, stored as DateTime
await col.QueryIndexAsync("idx_when", t0, t0.AddMinutes(5)).ToListAsync();
    // expected [m0, m5], actual ArgumentException: Cannot create IndexKey from type DateTime
await col.QueryIndexAsync("idx_when", new DateTimeOffset(t0).ToUnixTimeMilliseconds(),
    new DateTimeOffset(t0.AddMinutes(5)).ToUnixTimeMilliseconds()).ToListAsync();   // [m0, m5]
col.Query(BlqlFilter.Lte("when", t0.AddMinutes(5))).ToList();                        // [m0, m5], right

Expected: README.md:801 shows a date range on a dynamic index: var recent = orders.QueryIndex("idx_placed_at", minDate, maxDate);.

Mechanism (verified on 0450b97)

CreateIndexKeyFromObject (src/BLite.Core/DynamicCollection.cs:2804-2816) has no DateTime or DateTimeOffset case, although BsonValueToIndexKey keys both as Unix milliseconds in an IndexKey(long) (:2726-2730) and BLQL converts its bounds the same way before calling it (CompareFilter.ToIndexObject, src/BLite.Core/Query/Blql/BlqlFilter.cs:378). A long bound is taken as milliseconds, which works by accident.

Affected versions: since 39e6c89 (v1.4.0). Reproduced on v5.2.3 / 0450b97.

Fix considerations

  • DateTime and DateTimeOffset cases in CreateIndexKeyFromObject, keyed like the stored values (new IndexKey(new DateTimeOffset(d).ToUnixTimeMilliseconds()); the DateTimeKind of an unspecified DateTime should be treated the way the BSON writer treats it).
  • The README sample also uses the old synchronous names (QueryIndex, Near, Within), now QueryIndexAsync, NearAsync, WithinAsync.

Related: #269 (the decimal and bool bounds that throw in the same switch), #254 (open, the double keys), #140 (closed, DateTimeOffset round-trip).

Dominant language
C#
Stars
66
Forks
6
Avg merge
1d 2h
Merged PRs (30d)
43

Getting set up

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

More from EntglDb/BLite

All issues in EntglDb/BLite

Similar issues

More C# issues

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.