From e4fe62a3300bc2fcec4c7acd7b47e9cfbf4fed53 Mon Sep 17 00:00:00 2001 From: Tim Graham Date: Fri, 16 Aug 2024 21:03:26 -0400 Subject: [PATCH] remove broken write concern implementation This code came from django-mongodb-engine and doesn't work with the latest pymongo APIs. --- django_mongodb/base.py | 11 +---------- django_mongodb/compiler.py | 9 +++------ django_mongodb/query.py | 3 +-- 3 files changed, 5 insertions(+), 18 deletions(-) diff --git a/django_mongodb/base.py b/django_mongodb/base.py index 6bd1f196..252db9c2 100644 --- a/django_mongodb/base.py +++ b/django_mongodb/base.py @@ -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: diff --git a/django_mongodb/compiler.py b/django_mongodb/compiler.py index 7e49b02d..56a4c990 100644 --- a/django_mongodb/compiler.py +++ b/django_mongodb/compiler.py @@ -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 [] @@ -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() diff --git a/django_mongodb/query.py b/django_mongodb/query.py index 7aae4f89..db2b8adc 100644 --- a/django_mongodb/query.py +++ b/django_mongodb/query.py @@ -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):