New issue

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

Hard to understand error message when there is no database in URI #54

Closed
kissgyorgy opened this Issue Jan 28, 2015 · 1 comment

Comments

Projects
None yet
2 participants
@kissgyorgy

Mongodb documentation says that database part is optional:

/databse
Optional. The name of the database to authenticate if the connection string includes authentication credentials in the form of username:password@. If /database is not specified and the connection string includes credentials, the driver will authenticate to the admin database.

this library should default to that.
Also the error message is very hard to understand:

Traceback (most recent call last):
  File "connect_to_mongodb.py", line 12, in <module>
    mongo = PyMongo(app)
  File "/home/walkman/.virtualenvs/project/lib/python3.4/site-packages/flask_pymongo/__init__.py", line 98, in __init__
    self.init_app(app, config_prefix)
  File "/home/walkman/.virtualenvs/project/lib/python3.4/site-packages/flask_pymongo/__init__.py", line 235, in init_app
    db = cx[dbname]
  File "/home/walkman/.virtualenvs/project/lib/python3.4/site-packages/pymongo/mongo_client.py", line 1320, in __getitem__
    return self.__getattr__(name)
  File "/home/walkman/.virtualenvs/project/lib/python3.4/site-packages/flask_pymongo/wrappers.py", line 40, in __getattr__
    attr = super(MongoClient, self).__getattr__(name)
  File "/home/walkman/.virtualenvs/project/lib/python3.4/site-packages/pymongo/mongo_client.py", line 1309, in __getattr__
    return database.Database(self, name)
  File "/home/walkman/.virtualenvs/project/lib/python3.4/site-packages/pymongo/database.py", line 76, in __init__
    "of %s" % (str.__name__,))
TypeError: name must be an instance of str

The Exception thrown because database name will be None based on parsed MONGO_URI

@dcrosta dcrosta modified the milestone: 2.0 May 22, 2017

@dcrosta dcrosta added the BUG label May 22, 2017

@dcrosta

This comment has been minimized.

Show comment
Hide comment
@dcrosta

dcrosta May 22, 2017

Owner

Fixed in ab0fee2

Owner

dcrosta commented May 22, 2017

Fixed in ab0fee2

@dcrosta dcrosta closed this May 22, 2017

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment