michaelkryukov / mongomock_motor

Library for mocking AsyncIOMotorClient built on top of mongomock.
MIT License
94 stars 23 forks source link

Fix patches when fields are enum members #22

Closed ramnes closed 1 year ago

ramnes commented 1 year ago

The current implementation of _normalize_strings transforms enum members into their representation, when it should give their value instead.

For example, with such an enum

class Importance(str, Enum):
    HIGH = "high"
    LOW = "low"

a cursor like Cursor({"importance": Importance.HIGH}) would see its filter transformed to {"importance": "Importance.HIGH"} instead of {"importance": "high"}, which will most likely not fetch anything.

michaelkryukov commented 1 year ago

I looked into issue more closely – pymongo and mongomock actually work well with str-like classes (as I can tell), so issues are with interaction between mongomock and beanie's internals. Instead of adding this edge cases, I decided to add only ExpressionField as single edge case for now

michaelkryukov commented 1 year ago

You can checkout #23, and if everything's ok, I'll merge it, and close this one