Skip to content

Fix equality and hashcode contracts#847

Open
flyingsilverfin wants to merge 1 commit intotypedb:masterfrom
flyingsilverfin:driver-fixes
Open

Fix equality and hashcode contracts#847
flyingsilverfin wants to merge 1 commit intotypedb:masterfrom
flyingsilverfin:driver-fixes

Conversation

@flyingsilverfin
Copy link
Copy Markdown
Member

Usage and product changes

Streamline hash and equality contract differences:

  • Java uses Java-defined implementations of both equality and hash code, instead of just delegating equality to Rust and doing hashcode on the Java side.
  • Python's Datetime hash and equality both ignore timezone. Two Datetime objects representing the same instant in different timezones - following the Rust convention (as does CSharp. Java's native timezoned datetime that we defer to includes timezone in its contract)

Implementation

Java:

  • Removed final from ConceptImpl.equals() so ValueImpl can override it
  • Added ValueImpl.equals() using tryGetValueType().equals() && get().equals(), matching hashCode() which already uses get().hashCode()
  • DatetimeTZ follows Java's ZonedDateTime.equals() semantics (local time + zone + offset)

Python:

  • Removed _tz_name from Datetime.hash() tuple, restoring the hash-equality contract for timezone-aware datetimes

…lity

Value.equals() previously delegated to Rust's concept_equals via
ConceptImpl, while hashCode() used the Java-typed value from get().
This violated the equals/hashCode contract. Override equals() in
ValueImpl to use getValueType() + get().equals(), matching hashCode().

Fix Python Datetime.__hash__() to exclude timezone name from the hash
tuple, aligning with __eq__() which already compares by UTC instant.

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
@flyingsilverfin flyingsilverfin changed the title Fix Value equals/hashCode contract and datetime-tz instant-based equa… Fix equality and hashcode contracts Feb 24, 2026
@flyingsilverfin flyingsilverfin marked this pull request as ready for review February 24, 2026 22:44
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.

1 participant