Skip to content

Commit

Permalink
Give warning instead of error for wrong mongo URI (#2198)
Browse files Browse the repository at this point in the history
Quick fix for issue #2197 By raising a warning instead of an error optimade should still work. I leave it up to @ml-evs to make a more permanent solution. 
Removed needless check for self.mongo_database
  • Loading branch information
JPBergsma authored Dec 13, 2024
1 parent 9af05bc commit dde30a2
Showing 1 changed file with 4 additions and 2 deletions.
6 changes: 4 additions & 2 deletions optimade/server/config.py
Original file line number Diff line number Diff line change
Expand Up @@ -490,15 +490,17 @@ def align_mongo_uri_and_mongo_database(self) -> "ServerConfig":
"""
if self.database_backend == SupportedBackend.MONGODB:
if self.mongo_uri and self.mongo_database:
if self.mongo_uri:
import pymongo.uri_parser

if not self.mongo_uri.startswith(
"mongodb://"
) or self.mongo_uri.startswith("mongodb+srv://"):
self.mongo_uri = f"mongodb://{self.mongo_uri}"

uri: dict[str, Any] = pymongo.uri_parser.parse_uri(self.mongo_uri)
uri: dict[str, Any] = pymongo.uri_parser.parse_uri(
self.mongo_uri, warn=True
)
if uri.get("database"):
self.mongo_database = uri["database"]

Expand Down

0 comments on commit dde30a2

Please sign in to comment.