Repository navigation
Conversation
NodaTime returns null when two intervals share no day, but PostgreSQL's daterange * operator returns an empty range, so null tests on the result filtered the wrong rows. Translate to CASE WHEN a && b THEN a * b END. Fixes npgsql#4083
This branch has not been deployed
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Fixes #4083
NodaTime's
DateInterval.Intersectionreturnsnullwhen the two intervals share no day, but the translation used thedaterange * daterangeoperator, which returnsemptyfor disjoint ranges, never NULL. Because the result was also treated as non-nullable, null tests on it were folded away:== nullbecameWHERE FALSEand!= nulldropped the filter.This translates
Intersectionto:CASE WHEN a && b THEN a * b ENDwhich returns NULL when the ranges don't overlap. Because the CASE has no ELSE, EF's nullability processing now treats the result as nullable.
Tests
Intersectiontest.Intersection_with_disjoint_interval_is_nullandIntersection_with_disjoint_interval_not_null. Without the fix they return the wrong rows (expected 1/actual 0, and expected 0/actual 1).DateIntervalTranslationsTest: 24/24 pass. All NodaTime translation tests: 243/243 pass (PostgreSQL 17 + PostGIS 3.5).Not in this PR:
DateInterval.Unionhas a related mismatch, noted in #4083. It needs a different fix because PostgreSQL raises an error for non-contiguous unions. #4084 tracks the general nullability issue with PostgreSQL operators. This PR only fixesIntersection.