BeanieODM / beanie

Asynchronous Python ODM for MongoDB
http://beanie-odm.dev/
Apache License 2.0
2.02k stars 213 forks source link

[BUG] wrong condition convertion on comparing two fields #959

Open Karmenzind opened 3 months ago

Karmenzind commented 3 months ago

Describe the bug I need to compare two fields with model.field1 > model.field2 but Beanio generated the wrong filter.

My model is like:

class H(Document):
    last_sms_time: datetime
    next_sms_time: datetime

And H.find(H.next_sms_time < H.last_sms_time).get_filter_query() returned {'next_sms_time': {'$lt': 'last_sms_time'}} that compares next_sms_time with literal string 'last_sms_time'.

But the correct filter that will be recognized by Mongodb should be:

{"$expr": {"$lt": ["$next_sms_time", "$last_sms_time"]}}

or with $where:

{"$where": "this.next_sms_time < this.last_sms_time"}

To Reproduce Sorry I will complete the sample later.

Expected behavior See above.

Additional context Nothing.

github-actions[bot] commented 2 months ago

This issue is stale because it has been open 30 days with no activity.

github-actions[bot] commented 1 month ago

This issue was closed because it has been stalled for 14 days with no activity.