From b5a587d8d0b8f7b68eb67ac4c58a0c14aaba3012 Mon Sep 17 00:00:00 2001 From: cahrens Date: Tue, 19 Mar 2013 16:57:19 -0400 Subject: [PATCH] Have to explicitly specify safe option on mongo insert, remove, update because the debug toolbar specifies a default of safe=False. --- cms/envs/dev.py | 5 ++--- common/lib/xmodule/xmodule/modulestore/mongo.py | 13 +++++++++++-- 2 files changed, 13 insertions(+), 5 deletions(-) diff --git a/cms/envs/dev.py b/cms/envs/dev.py index f70f22512e..5612db1396 100644 --- a/cms/envs/dev.py +++ b/cms/envs/dev.py @@ -127,8 +127,7 @@ DEBUG_TOOLBAR_PANELS = ( 'debug_toolbar.panels.sql.SQLDebugPanel', 'debug_toolbar.panels.signals.SignalDebugPanel', 'debug_toolbar.panels.logger.LoggingPanel', -# This is breaking Mongo updates-- Christina is investigating. -# 'debug_toolbar_mongo.panel.MongoDebugPanel', + 'debug_toolbar_mongo.panel.MongoDebugPanel', # Enabling the profiler has a weird bug as of django-debug-toolbar==0.9.4 and # Django=1.3.1/1.4 where requests to views get duplicated (your method gets @@ -143,4 +142,4 @@ DEBUG_TOOLBAR_CONFIG = { # To see stacktraces for MongoDB queries, set this to True. # Stacktraces slow down page loads drastically (for pages with lots of queries). -# DEBUG_TOOLBAR_MONGO_STACKTRACES = False +DEBUG_TOOLBAR_MONGO_STACKTRACES = False diff --git a/common/lib/xmodule/xmodule/modulestore/mongo.py b/common/lib/xmodule/xmodule/modulestore/mongo.py index aceebbf15f..1bf4763723 100644 --- a/common/lib/xmodule/xmodule/modulestore/mongo.py +++ b/common/lib/xmodule/xmodule/modulestore/mongo.py @@ -493,7 +493,10 @@ class MongoModuleStore(ModuleStoreBase): try: source_item = self.collection.find_one(location_to_query(source)) source_item['_id'] = Location(location).dict() - self.collection.insert(source_item) + self.collection.insert(source_item, + # Must include this to avoid the django debug toolbar (which defines the deprecated "safe=False") + # from overriding our default value set in the init method. + safe=self.collection.safe) item = self._load_items([source_item])[0] # VS[compat] cdodge: This is a hack because static_tabs also have references from the course module, so @@ -556,6 +559,9 @@ class MongoModuleStore(ModuleStoreBase): {'$set': update}, multi=False, upsert=True, + # Must include this to avoid the django debug toolbar (which defines the deprecated "safe=False") + # from overriding our default value set in the init method. + safe=self.collection.safe ) if result['n'] == 0: raise ItemNotFoundError(location) @@ -626,7 +632,10 @@ class MongoModuleStore(ModuleStoreBase): course.tabs = [tab for tab in existing_tabs if tab.get('url_slug') != location.name] self.update_metadata(course.location, own_metadata(course)) - self.collection.remove({'_id': Location(location).dict()}) + self.collection.remove({'_id': Location(location).dict()}, + # Must include this to avoid the django debug toolbar (which defines the deprecated "safe=False") + # from overriding our default value set in the init method. + safe=self.collection.safe) # recompute (and update) the metadata inheritance tree which is cached self.get_cached_metadata_inheritance_tree(Location(location), force_refresh = True)