Skip to content

remove broken write concern implementation #107

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

Merged
merged 1 commit into from
Aug 19, 2024
Merged
Show file tree
Hide file tree
Changes from all 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
11 changes: 1 addition & 10 deletions django_mongodb/base.py
Original file line number Diff line number Diff line change
Expand Up @@ -148,19 +148,10 @@ def __getattr__(self, attr):

def _connect(self):
settings_dict = self.settings_dict

options = settings_dict["OPTIONS"]
# TODO: review and document OPERATIONS: https://github.com/mongodb-labs/django-mongodb/issues/6
self.operation_flags = options.pop("OPERATIONS", {})
if not any(k in ["save", "delete", "update"] for k in self.operation_flags):
# Flags apply to all operations.
flags = self.operation_flags
self.operation_flags = {"save": flags, "delete": flags, "update": flags}

self.connection = MongoClient(
host=settings_dict["HOST"] or None,
port=int(settings_dict["PORT"] or 27017),
**options,
**settings_dict["OPTIONS"],
)
db_name = settings_dict["NAME"]
if db_name:
Expand Down
9 changes: 3 additions & 6 deletions django_mongodb/compiler.py
Original file line number Diff line number Diff line change
Expand Up @@ -517,8 +517,7 @@ def execute_sql(self, returning_fields=None):
def insert(self, docs, returning_fields=None):
"""Store a list of documents using field columns as element names."""
collection = self.get_collection()
options = self.connection.operation_flags.get("save", {})
inserted_ids = collection.insert_many(docs, **options).inserted_ids
inserted_ids = collection.insert_many(docs).inserted_ids
return inserted_ids if returning_fields else []


Expand Down Expand Up @@ -582,15 +581,13 @@ def update(self, values):
return self.execute_update(spec)

@wrap_database_errors
def execute_update(self, update_spec, **kwargs):
def execute_update(self, update_spec):
collection = self.get_collection()
try:
criteria = self.build_query().mongo_query
except EmptyResultSet:
return 0
options = self.connection.operation_flags.get("update", {})
options = dict(options, **kwargs)
return collection.update_many(criteria, update_spec, **options).matched_count
return collection.update_many(criteria, update_spec).matched_count

def check_query(self):
super().check_query()
Expand Down
3 changes: 1 addition & 2 deletions django_mongodb/query.py
Original file line number Diff line number Diff line change
Expand Up @@ -58,8 +58,7 @@ def __repr__(self):
@wrap_database_errors
def delete(self):
"""Execute a delete query."""
options = self.connection.operation_flags.get("delete", {})
return self.collection.delete_many(self.mongo_query, **options).deleted_count
return self.collection.delete_many(self.mongo_query).deleted_count

@wrap_database_errors
def get_cursor(self):
Expand Down