Skip to content

Conversation

nadavge
Copy link

@nadavge nadavge commented Feb 19, 2022

It is "impossible" (or unconventional) to catch exceptions for an invalid ID, even though there's no good reason not to IMHO.

@juliusgeo
Copy link
Contributor

@nadavge Hi, I appreciate you opening this PR. That error is already importable--the following code for me runs fine on PyMongo 4.1 with Python 3.8.12 (in a new venv).

from bson.errors import InvalidId
try:
        pass
except InvalidId:
        # Handle exception
        pass

The only thing that your change allows is importing from the package namespace like so:

From bson import InvalidId

All of the other errors that are imported in bson/__init__.py are also used in that same file--hence the import. I believe that users are intended to import from bson.errors based on the PyMongo BSON documentation for errors.
Could I ask for the specific reason why you wish it to be in the packages namespace?

@pooooodles
Copy link

We're closing this out since we haven't heard anything further in this thread, but please let us know if you'd like to continue the conversation!

@pooooodles pooooodles closed this Feb 25, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants