Skip to content

fix: serialise OffsetDateTime as RFC 3339 - #609

Open
dudanogueira wants to merge 3 commits into
mainfrom
fix/rfc3339-dates
Open

dudanogueira wants to merge 3 commits into
mainfrom
fix/rfc3339-dates

Conversation

@dudanogueira

@dudanogueira dudanogueira commented Aug 25, 2026 •

Copy link
Copy Markdown

Problem

OffsetDateTime.toString() drops the seconds when they are zero, so 2024-03-01T00:00:00Z was sent as 2024-03-01T00:00Z. RFC 3339 requires the seconds, and Weaviate rejects the short form:

invalid date property 'when' on class 'X': requires a string with a RFC3339 formatted date,
but the given value is '2024-03-01T00:00Z'

Fix

  • Add DateUtil.toRFC3339, which always writes the seconds and keeps any fraction as it is.
  • Use it at all six places that send a date: the REST Gson adapter, Filter date and date-array operands, and InsertManyRequest for a single date, a List<OffsetDateTime> and an OffsetDateTime[].
  • Reading is unchanged: OffsetDateTime.parse already accepts both forms.

Breaking changes

None.

Closes #605

OffsetDateTime.toString() omits the seconds when the second and the
nanosecond are both zero, so a timestamp on an exact minute boundary
went on the wire as "2024-03-01T00:00Z". RFC 3339's partial-time
requires hour:minute:second, and the server rejects the short form --
breaking writes and filters alike for most timestamps written by hand.

DateUtil owned the read side but had no write-side counterpart, which
is why the same toString() was copy-pasted into all six marshalling
sites. It now has toRFC3339(), which always writes the seconds and
keeps the fraction variable-width so sub-second precision is neither
invented nor truncated.

The array and list variants in Filter and InsertManyRequest were
affected too, not just the three scalar sites in the report.

Reading is unchanged and stays lenient: OffsetDateTime.parse accepts
both forms, so timestamps written by older clients still load.

Closes #605

Co-Authored-By: Claude Opus 5 (1M context) <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01WmY5dAGWCccWDoqkKNC2JU

@orca-security-eu orca-security-eu Bot left a comment •

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Orca Security Scan Summary

Status Check Issues by priority
Passed Passed Infrastructure as Code high 0   medium 0   low 0   info 0 View in Orca
Passed Passed SAST high 0   medium 0   low 0   info 0 View in Orca
Passed Passed Secrets high 0   medium 0   low 0   info 0 View in Orca
Passed Passed Vulnerabilities high 0   medium 0   low 0   info 0 View in Orca

Copilot AI left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

This PR fixes OffsetDateTime wire serialization to always produce RFC 3339-compliant timestamps (notably always including seconds), preventing server-side rejections for minute-boundary values like 2024-03-01T00:00:00Z.

Changes:

  • Add DateUtil.toRFC3339(OffsetDateTime) backed by a custom DateTimeFormatterBuilder formatter that always prints seconds while preserving sub-second precision.
  • Update all affected gRPC/REST marshalling sites (filters and batch insert shapes) to use DateUtil.toRFC3339(...) instead of OffsetDateTime.toString().
  • Add/adjust unit + integration tests to cover minute-boundary timestamps and ensure round-tripping/parsing behavior remains compatible.

Reviewed changes

Copilot reviewed 7 out of 7 changed files in this pull request and generated 1 comment.

Show a summary per file
File Description
src/main/java/io/weaviate/client6/v1/internal/DateUtil.java Introduces RFC 3339 formatter + toRFC3339 and updates Gson adapter write path.
src/main/java/io/weaviate/client6/v1/api/collections/query/Filter.java Uses DateUtil.toRFC3339 for date filter operands (scalar + array).
src/main/java/io/weaviate/client6/v1/api/collections/data/InsertManyRequest.java Uses DateUtil.toRFC3339 for OffsetDateTime marshalling (scalar, list, array).
src/test/java/io/weaviate/client6/v1/internal/Rfc3339DateTest.java New focused unit tests for formatting, round-trip parsing, and marshalling at all relevant call sites.
src/test/java/io/weaviate/client6/v1/internal/json/JSONTest.java Adds JSON serialization expectations for OffsetDateTime including minute-boundary and fraction/offset cases.
src/it/java/io/weaviate/integration/SearchITest.java Adjusts integration test to use minute-boundary timestamps to guard the regression in filters.
src/it/java/io/weaviate/integration/DataITest.java Adjusts integration test to use minute-boundary timestamps to guard the regression in writes/round-trips.

💡 Add a code-review agent skill or configure MCP servers for context-aware, tailored reviews. Learn more in the docs.

Raised in review on #609: the formatter is built with toFormatter(), which
takes the default locale, so in a locale using non-Latin digits it could
emit a timestamp that is not RFC 3339.

The locale is not what chooses the digits. DecimalStyle is, and a builder
always starts from DecimalStyle.STANDARD -- measured on JDK 25,
DecimalStyle.of(Locale.forLanguageTag("hi-IN-u-nu-deva")) is
DecimalStyle[०+-.] and formatting through it does give
२०२४-०३-०१T००:००:००Z, but neither toFormatter() nor withLocale(...)
reaches that. Only an explicit withDecimalStyle(...) does, and nothing
calls it.

So there is nothing to fix, and this is a guard rather than a fix: it
fails if someone later gives the formatter a locale-derived decimal
style, which is the only route to the reported problem.

Co-Authored-By: Claude Opus 5 (1M context) <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01HNeKV7TAYZGDyT9agqJwUf
@dudanogueira

Copy link
Copy Markdown
Author

Looked into the Locale/DecimalStyle point — thanks, it sent me down a useful path, but the premise does not hold and toFormatter(Locale.ROOT) would not have addressed it.

The locale is not what selects the digits. DecimalStyle is, and a DateTimeFormatterBuilder always starts from DecimalStyle.STANDARD regardless of the locale it is given. Measured on JDK 25:

DecimalStyle.of(hi-IN-u-nu-deva) = DecimalStyle[०+-.]
DecimalStyle.STANDARD            = DecimalStyle[0+-.]

plain toFormatter()              -> 2024-03-01T00:00:00Z
withLocale(deva)                 -> 2024-03-01T00:00:00Z
withDecimalStyle(of(deva))       -> २०२४-०३-०१T००:००:००Z

So the mechanism the comment describes is real, but nothing here reaches it: only an explicit withDecimalStyle(...) changes the digits, and neither toFormatter() nor withLocale(...) does. Setting the default FORMAT locale to hi-IN-u-nu-deva, ar-EG-u-nu-arab or bn-BD-u-nu-beng leaves the output ASCII either way.

Rather than a no-op change I have added the invariant as a test (208f9ec4) — test_digitsAreAsciiInAnyLocale formats through DateUtil.toRFC3339 under those three locales. It has teeth: giving the formatter a locale-derived decimal style makes it fail with

[hi-IN-u-nu-deva] expected:<"[2024-03-01T00:00:00]Z"> but was:<"[२०२४-०३-०१T००:००:००]Z">

which is the only route to the problem as described. Unit suite green: 419 tests.

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

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

v6: OffsetDateTime is serialised with toString(), which drops the seconds and is not RFC 3339

2 participants