Skip to content

Regression tests for [JsonPropertyName] on temporal types (closes #4253)#4256

Merged
jeremydmiller merged 1 commit intomasterfrom
fix/4253-datetime-json-property-name
Apr 16, 2026
Merged

Regression tests for [JsonPropertyName] on temporal types (closes #4253)#4256
jeremydmiller merged 1 commit intomasterfrom
fix/4253-datetime-json-property-name

Conversation

@jeremydmiller
Copy link
Copy Markdown
Member

Closes #4253

Summary

The issue reported that [JsonPropertyName("ts")] on a DateTimeOffset property is ignored by Marten's LINQ provider — SQL emits (data ->> 'Timestamp') instead of (data ->> 'ts'), and CREATE INDEX DDL has the same issue.

After tracing the code paths on master (8.30.0), the obvious candidates all look correct:

  • QueryableMember base ctor sets RawLocator using member.ToJsonKey(casing) which honors [JsonPropertyName]
  • DateTimeOffsetMember, DateTimeMember, DateOnlyMember, TimeOnlyMember all inherit this base behavior
  • ComputedIndex resolves members through the same MemberFor path as LINQ

I wrote 8 regression tests mirroring the bug repro exactly. All 8 pass on master — the bug does not reproduce on the current code. The reporter may have been on an older build, or there's a reproduction step I'm missing.

Rather than keep the issue open without a reproducible repro, landing these regression tests to prevent future regressions across all temporal types.

Tests added

LINQ Where SQL (src/LinqTests/Acceptance/json_naming_attributes.cs):

  • recognize_stj_json_property_on_datetimeoffset_in_linq
  • recognize_stj_json_property_on_datetimeoffset_required_init_in_linq — uses the required { get; init; } shape from the bug report
  • recognize_stj_json_property_on_datetime_in_linq
  • recognize_stj_json_property_on_dateonly_in_linq
  • recognize_stj_json_property_on_timeonly_in_linq
  • end_to_end_query_with_datetimeoffset_json_property_name — end-to-end count query from the bug repro

Index DDL (src/DocumentDbTests/Indexes/computed_indexes.cs):

  • datetimeoffset_index_ddl_uses_json_property_name
  • datetimeoffset_required_init_index_ddl_uses_json_property_name

Test plan

  • All 6 LINQ tests pass on master (net9.0)
  • Both index DDL tests pass on master (net9.0)
  • End-to-end integration test with real PostgreSQL passes

🤖 Generated with Claude Code

Reporter claimed [JsonPropertyName] is ignored for DateTimeOffset
properties in both LINQ Where SQL and CREATE INDEX DDL. Tracing the
code paths showed QueryableMember.ctor correctly delegates to
ToJsonKey() for all types, including DateTimeOffsetMember, DateTimeMember,
DateOnlyMember, and TimeOnlyMember.

Added regression tests that mirror the bug repro exactly across:
- DateTime, DateTimeOffset, DateOnly, TimeOnly in LINQ Where SQL
- DateTimeOffset in CREATE INDEX DDL
- The { required; get; init; } property shape from the bug report
- End-to-end integration query

All tests pass on master; the bug does not reproduce. Keeping these
as regression coverage to prevent future regressions.

Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
@jeremydmiller jeremydmiller merged commit b28a6ff into master Apr 16, 2026
6 checks passed
@jeremydmiller jeremydmiller deleted the fix/4253-datetime-json-property-name branch April 16, 2026 17:28
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.

[JsonPropertyName] honored for int/enum, ignored for top-level DateTimeOffset — LINQ silently returns zero rows

1 participant