-
Notifications
You must be signed in to change notification settings - Fork 31
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
Automatically parse the dbname from the URI #350
Conversation
jmmshn
commented
Dec 2, 2020
- Read the database name from the URI, still allow the user-set value to supercede this.
@shyamd I need to access secrets to add a test for this. |
Codecov Report
@@ Coverage Diff @@
## master #350 +/- ##
==========================================
- Coverage 87.55% 87.35% -0.20%
==========================================
Files 28 28
Lines 2186 2191 +5
==========================================
Hits 1914 1914
- Misses 272 277 +5
Continue to review full report at Codecov.
|
You should be able to use a dummy URI to test if the parsing is working. |
OK awesome! I thought MongoClient needed to actually connect or something. Guess not |
src/maggma/stores/mongolike.py
Outdated
if database is None: | ||
with MongoClient(self.uri) as conn: | ||
try: | ||
db = conn.get_default_database() | ||
except ConfigurationError: | ||
raise ConfigurationError( | ||
"If database name is not supplied, a database must be set in the uri" | ||
) | ||
self.database = db.name | ||
else: | ||
self.database = database |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
does self.database
even need to be stored if it's not provided; IE, does anything break if database = None
? Also, this should probably be in connect
? Connection on init can be bad.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Ok using the Mongoclient there was a little hacky.
I have changed it.
Technically the code will not break if database == None
but it will break if database == None
and no value is found in the URI.
I do think the database
should be kept since every Mongo-like store must have a database anyways.