8000 Fix behavior for $type filter on numeric types by guludo · Pull Request #755 · mongomock/mongomock · GitHub
[go: up one dir, main page]
More Web Proxy on the site http://driver.im/
Skip to content

Fix behavior for $type filter on numeric types #755

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Feb 17, 2022

Conversation

guludo
Copy link
Contributor
@guludo guludo commented Feb 6, 2022

Hi there.

This is the first of 3 PRs made from splitting #743.

This makes changes so that we:

  • Use correct type for "decimal"
  • Ensure that we do not confuse a Python bool for an int (since
    isinstance(True, int) evaluates as True).
  • Check on the bit-length of int values to check whether they should
    be considered "int" or "long" from Mongo's perspective.

This patch adds the missing test for $type in test__mongomock.py. Note
that the "array" type was purposefully ignored from supported_types,
as there is an issue that will be solved in a future patch:
_type_op([1, 2, 3], t) should return True for both t = 'array' and
t = 'int'.

@codecov
Copy link
codecov bot commented Feb 6, 2022

Codecov Report

Merging #755 (f940150) into develop (5e38e97) will increase coverage by 0.00%.
The diff coverage is 100.00%.

Impacted file tree graph

@@           Coverage Diff            @@
##           develop     #755   +/-   ##
========================================
  Coverage    95.14%   95.15%           
========================================
  Files           19       19           
  Lines         3731     3735    +4     
========================================
+ Hits          3550     3554    +4     
  Misses         181      181           
Impacted Files Coverage Δ
mongomock/filtering.py 99.02% <100.00%> (+0.01%) ⬆️

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 5e38e97...f940150. Read the comment docs.

@guludo
Copy link
Contributor Author
guludo commented Feb 6, 2022

Force-pushed with changes required (comments where posted in #756).

@pcorpet
Copy link
Member
pcorpet commented Feb 7, 2022

Please apply all the changes we added in #755 to simplify the map.

@guludo
Copy link
Contributor Author
guludo commented Feb 7, 2022

Please apply all the changes we added in #755 to simplify the map.

I'm not sure I follow. This is #755. Did you mean to squash #756 into this?

@pcorpet
Copy link
Member
pcorpet commented Feb 9, 2022

Yes, sorry, I didn't mean to merge them, but all the remarks I made on #756 actually apply here.
Have TYPE_MAP be only about predicates.

- Use correct type for "decimal"
- Ensure that we do not confuse a Python `bool` for an `int` (since
  `isinstance(True, int)` evaluates as True).
- Check on the bit-length of `int` values to check whether they should
  be considered "int" or "long" from Mongo's perspective.

This patch adds the missing test for $type in `test__mongomock.py`. Note
that the "array" type was purposefully ignored from `supported_types`,
as there is an issue that will be solved in a future patch:
`_type_op([1, 2, 3], t)` should return True for both `t = 'array'` and
`t = 'int'`.
@guludo guludo force-pushed the pr/fix-type-for-numerics branch from 465d3fd to f940150 Compare February 15, 2022 13:05
@guludo
Copy link
Contributor Author
guludo commented Feb 15, 2022

Hi @pcorpet,

Just updated this to have TYPE_MAP use only predicates. I preferred to use lambdas for all of them instead of adding a new function _create_type_predicate.

@pcorpet pcorpet merged commit 98a5254 into mongomock:develop Feb 17, 2022
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.

2 participants
0