Skip to content

Report $out and planCacheSetFilter failures through the assertion - #729

Merged
eerxuan merged 4 commits into
documentdb:mainfrom
samafarc:investigate-out-geo-filters
Nov 6, 2026
Merged

eerxuan merged 4 commits into
documentdb:mainfrom
samafarc:investigate-out-geo-filters

Conversation

@samafarc

@samafarc samafarc commented Oct 19, 2026 •

Copy link
Copy Markdown
Contributor

Summary

Some tests crash with a Python error before they reach the assertion when an engine rejects a command. The real engine error is then hidden. This PR routes those failures through the existing assertion helpers, so the report shows what the engine returned.

$out tests (test_out_acceptance.py, test_out_timeseries.py, test_out_write_behavior.py)
These tests ran $out, ignored its result, and then read listCollections.cursor.firstBatch[0]. If the engine rejects $out, the batch is empty and the test crashes with IndexError. The tests now keep the $out result. If it is an exception, it goes straight to assertSuccess, which reports the engine error (for example code 40415 "BSON field '$out.timeseries' is an unknown field."). If $out succeeds, the listCollections check runs as before. In stages/out/, these three files are the only ones with this pattern.

planCacheSetFilter tests (test_planCacheSetFilter_cross_command.py, test_planCacheSetFilter_effectiveness.py, test_planCacheSetFilter_partial_sparse.py)
These tests read queryPlanner["indexFilterSet"]. If an engine leaves the field out of explain, the test crashes with KeyError. indexFilterSet is the property under test, so the tests now read it with .get(). A missing field then shows up as an assertion mismatch (expected True, got None). MongoDB always returns the field, so nothing changes there.

Each test still has a single assertion. No expected values change.

Testing

  • pre-commit (black, isort, flake8, mypy) passes on all changed files.
  • pytest -m unit: 152 passed.
  • MongoDB 8.2.4 replica set, all 6 changed files: 100 passed on this branch and 100 passed on main (out_acceptance 31, out_timeseries 26, out_write_behavior 19, planCacheSetFilter cross_command 12 / effectiveness 8 / partial_sparse 4).
  • I stubbed the executor so that $out returns an OperationFailure, then ran test_out_database_name_acceptance. On main it raises IndexError: list index out of range. On this branch it raises AssertionError: [UNEXPECTED_ERROR] Expected success but got exception: {'code': 40415, ...}.

@samafarc
samafarc requested a review from a team as a code owner October 19, 2026 20:20

@eerxuan eerxuan left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

Summary

Turns two crash-on-unsupported patterns into assertion failures: the $out tests index
into listCollections after a failed $out, and the planCacheSetFilter tests subscript
indexFilterSet. I checked the $out change with a stubbed executor that makes $out
fail: main raises IndexError, this branch raises an AssertionError carrying the
engine's error. CI is green on both mongo targets. One file with the same $out pattern
is not covered (item 1).

Critical Issues

  1. [Required] test_out_write_behavior.py:100 has the same crash and is not changed.
    test_out_database_name_acceptance calls $out, discards the result, then reads
    cast(dict, result)["cursor"]["firstBatch"][0] from listCollections. An engine that
    rejects $out still gets an IndexError there. It is the third file with this pattern
    (grep 'firstBatch"\]\[0\]' in stages/out/ finds exactly these three). Please apply
    the same fix, or say why this file is excluded.

Positive Feedback

  • The root cause is correctly identified: the crash hides the engine's actual error.
  • The scope is small, and the description says what was run (57 and 24 passed on MongoDB 8.2.4).
  • .get() for indexFilterSet is correct for the assertion. A missing field yields None,
    which Eq(True) rejects, so no test can switch from failing to passing.

Signed-off-by: Samar Farooqi <samafarc@amazon.com>
…lter tests

Signed-off-by: Samar Farooqi <samafarc@amazon.com>
…ior tests

Signed-off-by: Samar Farooqi <samafarc@amazon.com>
@samafarc
samafarc force-pushed the investigate-out-geo-filters branch from dff5182 to cf44ec7 Compare November 6, 2026 00:40
@samafarc

samafarc commented Nov 6, 2026

Copy link
Copy Markdown
Contributor Author

Thanks @eerxuan, good catch.

  1. test_out_write_behavior.py:100: test_out_database_name_acceptance now gets the same fix. The $out result is kept, and an error goes straight to assertSuccess. stages/out/ has no other copies of the pattern. With a stubbed failing $out, main raises IndexError and this branch raises an AssertionError carrying the engine error.

Also rebased onto current main (10eec47) and updated the description and test counts (100/100 on MongoDB 8.2.4, same as main).

@documentdb-triage-tool documentdb-triage-tool Bot added bug Something isn't working compatibility test Compatibility test related labels Nov 6, 2026
@documentdb-triage-tool

Copy link
Copy Markdown

🤖 Auto-triaged by documentdb-triage-tool.

Applied: compatibility test, bug
Project fields suggested: Component test-coverage · Priority P0 · Effort L · Status Needs Review
Confidence: 0.85 (mixed)

Reasoning

component from path globs (test-coverage); P0 keyword "crash" in body; effort from diff stats (78+59 LOC, 6 files); LLM: Fixes masked test failures where engine errors cause Python crashes (IndexError/KeyError) before reaching assertions, routing them through the standard assertion helpers for proper error reporting.

If a label is wrong, remove it manually and ping @patty-chow so the rules can be tuned. The bot will not re-label items that already have component labels.

@eerxuan
eerxuan merged commit 305b3e8 into documentdb:main Nov 6, 2026
20 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

bug Something isn't working compatibility test Compatibility test related

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants