diff --git a/cms/djangoapps/contentstore/features/transcripts.py b/cms/djangoapps/contentstore/features/transcripts.py index 4e70912c3d..0783d01fea 100644 --- a/cms/djangoapps/contentstore/features/transcripts.py +++ b/cms/djangoapps/contentstore/features/transcripts.py @@ -171,7 +171,7 @@ def remove_transcripts_from_store(_step, subs_id): ) try: content = contentstore().find(content_location) - contentstore().delete(content.get_id()) + contentstore().delete(content.location) print('Transcript file was removed from store.') except NotFoundError: print('Transcript file was NOT found and not removed.') diff --git a/cms/djangoapps/contentstore/tests/test_transcripts_utils.py b/cms/djangoapps/contentstore/tests/test_transcripts_utils.py index e00e3fdad1..f0272764b4 100644 --- a/cms/djangoapps/contentstore/tests/test_transcripts_utils.py +++ b/cms/djangoapps/contentstore/tests/test_transcripts_utils.py @@ -88,7 +88,7 @@ class TestSaveSubsToStore(ModuleStoreTestCase): """Remove, if subtitles content exists.""" try: content = contentstore().find(self.content_location) - contentstore().delete(content.get_id()) + contentstore().delete(content.location) except NotFoundError: pass @@ -171,7 +171,7 @@ class TestDownloadYoutubeSubs(ModuleStoreTestCase): content_location = StaticContent.compute_location(self.course.id, filename) try: content = contentstore().find(content_location) - contentstore().delete(content.get_id()) + contentstore().delete(content.location) except NotFoundError: pass diff --git a/common/lib/xmodule/xmodule/contentstore/content.py b/common/lib/xmodule/xmodule/contentstore/content.py index c6e8b58be4..8b9f6706af 100644 --- a/common/lib/xmodule/xmodule/contentstore/content.py +++ b/common/lib/xmodule/xmodule/contentstore/content.py @@ -59,7 +59,7 @@ class StaticContent(object): ) def get_id(self): - return self.location.to_deprecated_son(tag=XASSET_LOCATION_TAG) + return self.location def get_url_path(self): return self.location.to_deprecated_string() diff --git a/common/lib/xmodule/xmodule/contentstore/mongo.py b/common/lib/xmodule/xmodule/contentstore/mongo.py index 6aac2a43b0..d80819faea 100644 --- a/common/lib/xmodule/xmodule/contentstore/mongo.py +++ b/common/lib/xmodule/xmodule/contentstore/mongo.py @@ -12,7 +12,7 @@ from xmodule.exceptions import NotFoundError from fs.osfs import OSFS import os import json -import bson.son +from bson.son import SON from xmodule.modulestore.locations import AssetLocation @@ -29,7 +29,7 @@ class MongoContentStore(ContentStore): pymongo.MongoClient( host=host, port=port, - document_class=bson.son.SON, + document_class=SON, **kwargs ), db @@ -43,7 +43,7 @@ class MongoContentStore(ContentStore): self.fs_files = _db[bucket + ".files"] # the underlying collection GridFS uses def save(self, content): - content_id = content.get_id() + content_id = self.asset_db_key(content.location) # Seems like with the GridFS we can't update existing ID's we have to do a delete/add pair self.delete(content_id) @@ -71,13 +71,6 @@ class MongoContentStore(ContentStore): def find(self, location, throw_on_not_found=True, as_stream=False): content_id = self.asset_db_key(location) - fs_pointer = self.fs_files.find_one(content_id, fields={'_id': 1}) - if fs_pointer is None: - if throw_on_not_found: - raise NotFoundError() - else: - return None - content_id = fs_pointer['_id'] try: if as_stream: @@ -104,13 +97,13 @@ class MongoContentStore(ContentStore): ) except NoFile: if throw_on_not_found: - raise NotFoundError() + raise NotFoundError(content_id) else: return None def get_stream(self, location): content_id = self.asset_db_key(location) - fs_pointer = self.fs_files.find_one(content_id, fields={'_id': 1}) + fs_pointer = self.fs_files.find_one({'_id': content_id}, fields={'_id': 1}) try: handle = self.fs.get(fs_pointer['_id']) @@ -246,10 +239,10 @@ class MongoContentStore(ContentStore): raise AttributeError("{} is a protected attribute.".format(attr)) asset_db_key = self.asset_db_key(location) # FIXME remove fetch and use a form of update which fails if doesn't exist - item = self.fs_files.find_one(asset_db_key) + item = self.fs_files.find_one({'_id': asset_db_key}) if item is None: raise NotFoundError(asset_db_key) - self.fs_files.update(asset_db_key, {"$set": attr_dict}) + self.fs_files.update({'_id': asset_db_key}, {"$set": attr_dict}) def get_attrs(self, location): """ @@ -262,7 +255,7 @@ class MongoContentStore(ContentStore): :param location: a c4x asset location """ asset_db_key = self.asset_db_key(location) - item = self.fs_files.find_one(asset_db_key) + item = self.fs_files.find_one({'_id': asset_db_key}) if item is None: raise NotFoundError(asset_db_key) return item diff --git a/lms/djangoapps/courseware/tests/test_video_handlers.py b/lms/djangoapps/courseware/tests/test_video_handlers.py index 4e332c91a8..570fa0e0bc 100644 --- a/lms/djangoapps/courseware/tests/test_video_handlers.py +++ b/lms/djangoapps/courseware/tests/test_video_handlers.py @@ -67,8 +67,7 @@ def _clear_assets(location): for asset in assets: asset_location = AssetLocation._from_deprecated_son(asset["_id"], location.course_key.run) del_cached_content(asset_location) - mongo_id = asset_location.to_deprecated_son() - store.delete(mongo_id) + store.delete(asset_location) def _get_subs_id(filename):