Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Conversation

@ml-evs
Copy link
Contributor

@ml-evs ml-evs commented May 24, 2021

Closes #710 and looks related to the fixes in #697.

Currently, if a missing field is queried with {field: {"$size": 1}}, all documents without that field will match, as bool(NOTHING) evaluates to True.

This PR checks explicitly whether the missing field $size is NOTHING (indicating that the field value could not be parsed as an array, see #697).

The first commit in this PR adds a test for the current bug (so the CI should fail), and the second provides the fix.

@codecov
Copy link

codecov bot commented May 24, 2021

Codecov Report

❗ No coverage uploaded for pull request base (develop@b79b599). Click here to learn what that means.
The diff coverage is 100.00%.

Impacted file tree graph

@@            Coverage Diff             @@
##             develop     #711   +/-   ##
==========================================
  Coverage           ?   95.38%           
==========================================
  Files              ?       19           
  Lines              ?     3640           
  Branches           ?        0           
==========================================
  Hits               ?     3472           
  Misses             ?      168           
  Partials           ?        0           
Impacted Files Coverage Ξ”
mongomock/filtering.py 99.00% <100.00%> (ΓΈ)

Continue to review full report at Codecov.

Legend - Click here to learn more
Ξ” = absolute <relative> (impact), ΓΈ = not affected, ? = missing data
Powered by Codecov. Last update b79b599...8057ca6. Read the comment docs.

@ml-evs ml-evs marked this pull request as ready for review May 24, 2021 12:48
@ml-evs ml-evs changed the title Add check for missing field when querying $size Fix for {$size: 1} queries on non-existent fields May 24, 2021
@pcorpet
Copy link
Member

pcorpet commented May 24, 2021

Thanks for spotting and fixing that bug.

@pcorpet pcorpet merged commit e46c39b into mongomock:develop May 24, 2021
@ml-evs
Copy link
Contributor Author

ml-evs commented May 24, 2021

No problem @pcorpet, thanks for the quick review. mongomock is super useful for testing and validation over at https://github.com/Materials-Consortia/optimade-python-tools and https://www.optimade.org/, so thanks for all your hard work.

I don't know what your release schedule is, but we would really appreciate a patch release for this, if that works for you!

@ml-evs ml-evs deleted the ml-evs/close_#797 branch May 24, 2021 20:53
@pcorpet
Copy link
Member

pcorpet commented May 25, 2021

Thanks for the kind words, I'll try to get few more fixes in and then release.

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.

{<field>: {"$size": 1}} returns documents with <field> missing

2 participants