We read every piece of feedback, and take your input very seriously.
To see all available qualifiers, see our documentation.
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
Describe the bug when using multiple ExpressionField only the first sorting argument reach mongo
ExpressionField
To Reproduce
import asyncio import structlog from beanie import Document, init_beanie from beanie.odm.enums import SortDirection from motor.motor_asyncio import AsyncIOMotorClient from pymongo import monitoring from pymongo.monitoring import CommandStartedEvent, CommandSucceededEvent, CommandFailedEvent logger = structlog.get_logger("beanie test") class CommandLogger(monitoring.CommandListener): def started(self, event: CommandStartedEvent): if event.command_name == "find": logger.debug( f"mongo {event.command_name} started", command=event.command, ) def succeeded(self, event: CommandSucceededEvent): pass def failed(self, event: CommandFailedEvent): pass class MyModel(Document): int_number: int is_boolean: bool class Settings: name = "my_model" async def main(): await init_beanie(AsyncIOMotorClient(event_listeners=[CommandLogger()])["test_hs_das"], document_models=[MyModel]) sort1 = [+MyModel.int_number, +MyModel.is_boolean] sort2 = [("int_number", SortDirection.ASCENDING), "-is_boolean"] logger.info(sort1) logger.info(sort2) await MyModel.find().sort(sort1).to_list() await MyModel.find().sort(sort2).to_list() if __name__ == '__main__': asyncio.run(main())
Expected behavior I expect that when using
await MyModel.find().sort( [+MyModel.int_number,+MyModel.is_boolean]).to_list()
the logger output will be
2023-01-02 16:19:22 [debug ] mongo find started command=SON([('find', 'my_model'), ('filter', {}), ('sort', SON([('int_number', <SortDirection.ASCENDING: 1>), ('is_boolean', <SortDirection.DESCENDING: -1>)])), ...
('sort', SON([('int_number', <SortDirection.ASCENDING: 1>), ('is_boolean', <SortDirection.DESCENDING: -1>)]))
but is
2023-01-02 16:19:22 [debug ] mongo find started command=SON([('find', 'my_model'), ('filter', {}), ('sort', SON([('int_number', <SortDirection.ASCENDING: 1>)]))
('sort', SON([('int_number', <SortDirection.ASCENDING: 1>)]))
it does work when NOT using ExpressionField
await MyModel.find().sort([("int_number", SortDirection.ASCENDING), "-is_boolean"]).to_list()
The text was updated successfully, but these errors were encountered:
Hey @nadir-albajari-hs , Thank you for the catch. It is solved here: #468 Will be merged tomorrow
Sorry, something went wrong.
@nadir-albajari-hs Please try the current version
roman-right
No branches or pull requests
Describe the bug
when using multiple
ExpressionField
only the first sorting argument reach mongoTo Reproduce
Expected behavior
I expect that when using
the logger output will be
but is
it does work when NOT using
ExpressionField
The text was updated successfully, but these errors were encountered: