Add $toDate test cases from $convert tests#101
Merged
eerxuan merged 5 commits intodocumentdb:mainfrom Apr 17, 2026
Merged
Conversation
Signed-off-by: Daniel Frankcom <frankcom@amazon.com>
Collaborator
Author
|
The 16 test failures for CI are expected. They are the 4 parameterized cases for the following: Once #79 is merged I can mark these as expected failures for MongoDB, but I don't want to duplicate the framework effort for adding that machinery. |
Signed-off-by: Daniel Frankcom <frankcom@amazon.com>
Signed-off-by: Daniel Frankcom <frankcom@amazon.com>
Signed-off-by: Daniel Frankcom <frankcom@amazon.com>
yshanhu
approved these changes
Apr 17, 2026
eerxuan
approved these changes
Apr 17, 2026
Signed-off-by: Daniel Frankcom <frankcom@amazon.com>
eerxuan
approved these changes
Apr 17, 2026
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.
This change expands
$toDatetest coverage with cases uncovered while testing$convert.The main addition is the
DATETOSTRING_YEAR_RANGE_ERRORerror code and tests around year parsing. The behavior around the year parsing logic is quite strange, and in some cases MongoDB returns years which are unparseable by the BSON driver.It's not overly clear why the MongoDB range and Python range differ, and it's hard to say if the mismatch points to a bug or not. As a result this adds a new
assertExceptionTypehelper which allows us to assert the BSON driver throws an exception based on the result. This is the current behavior when testing against MongoDB, so it seems like part of the spec even though it's unusual.There is also a likely bug observed when testing against MongoDB: when a date string has more than 4 digits before the first
-,$toDatesilently produces a wrong date instead of rejecting the input. The parser reads the first 4 characters as the year, and when that value exceeds2059, it falls back to re-parsing from the 5th character using a short year format. DocumentDB does not exhibit this behavior and correctly rejects these inputs.The fallback applies a 2-digit year cutoff at 2059:
2059(e.g.20599): correctly rejected2059(e.g.20609): silently misparses remainderThis affects any digit count, even a 50-digit year string is silently accepted and misparsed. Both sides of the 2059 boundary are tested, along with longer digit sequences. The tests assert the expected correct behavior (rejection), which DocumentDB already implements.
Other new test cases include:
+HH:MM,+HHMM,-00:00,+00, etc.)$yearextraction (years -1, 0, 10000)$convert integration
Moves
test_smoke_toDate.pyfromdate/toDate/totype/toDate/to collocate it with the detailed tests and other similar operators.Adds minimal
convert_exprandconvert_field_exprhelpers inconvert/utils/convert_common.py, and parametrizestest_toDate_basic.pyandtest_toDate_expressions.pyover both the native$toDateoperator and the equivalent$convertexpression. This follows the pattern established for$toStringand applied to allto*operators, since forms of$convertare aliases for these operators.Ref: #15