Move DBModel._id -> DBModel.id

We were refering to model._id in most of the code base as this is
what Mongo uses. However, each use of _id required a) fixup of queries:
e.g. what we did in our find() and find_one() functions moving all
'_id' to 'id'. It also required using AliasFields to make the ._id
attribute available. This all means lots of superfluous fixing and
transitioning in a SQL world.

It will also not work in the long run. Much newer code already refers
to the objects by model.id (e.g. in the oauth plugin), which will break
with Mongo. So let's be honest, rip out the _id mongoism and live with
.id as the one canonical way to address objects.

This commit modifies all users and providers of model._id to use
model.id instead. This patch works with or without Mongo removed first,
but will break Mongo usage (even more than before)

I have not bothered to fixup db.mongo.* and db.sql.convert
(which converts from Mongo to SQL)

Signed-off-by: Sebastian Spaeth <Sebastian@SSpaeth.de>
This commit is contained in:
Sebastian Spaeth
2012-11-30 10:49:06 +01:00
parent 7e55bcb898
commit 5c2b84869f
30 changed files with 96 additions and 119 deletions

View File

@@ -38,7 +38,7 @@ class ProgressCallback(object):
def create_pub_filepath(entry, filename):
return mgg.public_store.get_unique_filepath(
['media_entries',
unicode(entry._id),
unicode(entry.id),
filename])
@@ -93,7 +93,7 @@ def mark_entry_failed(entry_id, exc):
# Looks like yes, so record information about that failure and any
# metadata the user might have supplied.
atomic_update(mgg.database.MediaEntry,
{'_id': entry_id},
{'id': entry_id},
{u'state': u'failed',
u'fail_error': unicode(exc.exception_path),
u'fail_metadata': exc.metadata})
@@ -104,7 +104,7 @@ def mark_entry_failed(entry_id, exc):
# metadata (in fact overwrite it if somehow it had previous info
# here)
atomic_update(mgg.database.MediaEntry,
{'_id': entry_id},
{'id': entry_id},
{u'state': u'failed',
u'fail_error': None,
u'fail_metadata': {}})

View File

@@ -42,7 +42,7 @@ class ProcessMedia(Task):
(for now just process_image...)
"""
entry = mgg.database.MediaEntry.one(
{'_id': ObjectId(media_id)})
{'id': ObjectId(media_id)})
# Try to process, and handle expected errors.
try:
@@ -61,7 +61,7 @@ class ProcessMedia(Task):
json_processing_callback(entry)
except BaseProcessingFail as exc:
mark_entry_failed(entry._id, exc)
mark_entry_failed(entry.id, exc)
json_processing_callback(entry)
return
@@ -72,7 +72,7 @@ class ProcessMedia(Task):
entry.title,
exc))
mark_entry_failed(entry._id, exc)
mark_entry_failed(entry.id, exc)
json_processing_callback(entry)
except Exception as exc:
@@ -80,7 +80,7 @@ class ProcessMedia(Task):
+ ' processing {0}'.format(
entry))
mark_entry_failed(entry._id, exc)
mark_entry_failed(entry.id, exc)
json_processing_callback(entry)
raise