Skip to content
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

Custom database name #3279

Open
wants to merge 4 commits into
base: development
Choose a base branch
from
Open
Changes from 3 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 5 additions & 2 deletions core/clients.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@
from aiohttp import ClientResponseError, ClientResponse
from motor.motor_asyncio import AsyncIOMotorClient
from pymongo.errors import ConfigurationError
from pymongo.uri_parser import parse_uri

from core.models import InvalidConfigError, getLogger

Expand Down Expand Up @@ -445,7 +446,8 @@ def __init__(self, bot):
raise RuntimeError

try:
db = AsyncIOMotorClient(mongo_uri).modmail_bot
database = parse_uri(mongo_uri).get('database') or 'modmail_bot'
db = AsyncIOMotorClient(mongo_uri)[database]
except ConfigurationError as e:
logger.critical(
"Your MongoDB CONNECTION_URI might be copied wrong, try re-copying from the source again. "
Expand Down Expand Up @@ -497,7 +499,8 @@ async def validate_database_connection(self, *, ssl_retry=True):
'run "Certificate.command" on MacOS, '
'and check certifi is up to date "pip3 install --upgrade certifi".'
)
self.db = AsyncIOMotorClient(mongo_uri, tlsAllowInvalidCertificates=True).modmail_bot
database = parse_uri(mongo_uri).get('database') or 'modmail_bot'
self.db = AsyncIOMotorClient(mongo_uri, tlsAllowInvalidCertificates=True)[database]
return await self.validate_database_connection(ssl_retry=False)
if "ServerSelectionTimeoutError" in message:
logger.critical(
Expand Down