Skip to content

Commit

Permalink
fix: mongo connection should not fail if proxy is provided
Browse files Browse the repository at this point in the history
also, remove empty lines to make pycodestyle happy
  • Loading branch information
kdmccormick committed Sep 27, 2024
1 parent 5e139ce commit 267d982
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 7 deletions.
1 change: 0 additions & 1 deletion xmodule/contentstore/mongo.py
Original file line number Diff line number Diff line change
Expand Up @@ -290,7 +290,6 @@ def remove_redundant_content_for_courses(self):
self.fs_files.remove(query)
return assets_to_delete


def _get_all_content_for_course(self,
course_key,
get_thumbnails=False,
Expand Down
13 changes: 7 additions & 6 deletions xmodule/mongo_utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -22,23 +22,24 @@
def connect_to_mongodb(
db, host,
port=27017, tz_aware=True, user=None, password=None,
retry_wait_time=0.1, proxy=True, **kwargs
retry_wait_time=0.1, **kwargs
):
"""
Returns a MongoDB Database connection, optionally wrapped in a proxy. The proxy
handles AutoReconnect errors by retrying read operations, since these exceptions
typically indicate a temporary step-down condition for MongoDB.
Returns a MongoDB Database connection.
"""
# If the MongoDB server uses a separate authentication database that should be specified here.
# Convert the lowercased authsource parameter to the camel-cased authSource expected by MongoClient.
auth_source = db
if auth_source_key := {'authSource', 'authsource'}.intersection(set(kwargs.keys())):
auth_source = kwargs.pop(auth_source_key.pop()) or db

# sanitize a kwarg which may be present and is no longer expected
# AED 2020-03-02 TODO: Remove this when 'auth_source' will no longer exist in kwargs
# sanitize kwargs which may be present and is no longer expected
if 'auth_source' in kwargs:
logger.warning("Bad MongoDB connection parameter: auth_source. Use authSource or authsource instead.")
kwargs.pop('auth_source')
if 'proxy' in kwargs:
logger.warning("Obselete MongoDB connection parameter: proxy. Connection is always proxied now.")
kwargs.pop("proxy")

# If read_preference is given as a name of a valid ReadPreference.<NAME>
# constant such as "SECONDARY_PREFERRED" or a mongo mode such as
Expand Down

0 comments on commit 267d982

Please sign in to comment.