BeanieODM / beanie

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

Python Exception Chaining #871

Closed roshanr10 closed 1 month ago

roshanr10 commented 4 months ago

Currently a few exceptions are lost due to the way Beanie handles the try/except & raise approach – using exception chaining / re-raising the same exception ensures the appropriate values can be used for debugging downstream.

Especially with DuplicateKeyError, it's incredibly unclear to the user when they get a RevisionIdWasChanged instead with no way to trace it back to a DuplicateKeyError.

roman-right commented 4 months ago

Hi @roshanr10 , Thank you very much for the PR! Could you please add a test for this case?

roshanr10 commented 3 months ago

Hi @roman-right , thanks for the update, following up on this – can you please provide more insight into why DuplicateKeyError is being caught? As far as I've experienced, there is no unique ID index on the revision id, so it would never be caught in normal usage.

this is what I've done to get information from the underlying DuplicateKeyError but not sure why it's intercepted

except beanie.exceptions.RevisionIdWasChanged as e:
    if e.__context__.details["keyPattern"]["<YOUR_KEY_PATTERN"] == 1:
        # HANDLE
github-actions[bot] commented 2 months ago

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

github-actions[bot] commented 1 month ago

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