BeanieODM / beanie

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

fix: reset operations after commit #721

Closed wouter-n closed 10 months ago

wouter-n commented 1 year ago

Context:

I found this issue when batching many requests to a bulk writer and manually committing 10'000 operations at a time (see pseudo code below)

async with BulkWriter() as bulk_writer:
    for counter, item in enumerate(items):
        # Do operations with bulk_writer

        if counter % 10000 == 0:
            bulk_writer.commit()

What:

Reset the operations attribute after the operations have been committed in the bulk writer

Why:

To ensure that after committing the list of operations is not done twice after a manual call of commit()

Please let me know if I missed something or I'm using the bulk writer in the wrong way but this very much looks like a bug.

roman-right commented 1 year ago

Interesting use-case. Thank you for the PR! Could you please add a test? Using $inc operation for example

github-actions[bot] commented 10 months ago

This PR is stale because it has been open 45 days with no activity.

github-actions[bot] commented 10 months ago

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