Fix #1017 - Exception caused by activity being set on incorrect foreign key
authorJessica Tallon <jessica@megworld.co.uk>
Wed, 29 Oct 2014 08:47:09 +0000 (08:47 +0000)
committerJessica Tallon <jessica@megworld.co.uk>
Wed, 29 Oct 2014 08:47:12 +0000 (08:47 +0000)
The .activity ForeignKey on several models such as MediaEntry expects
a ActivityIntmediatory ID not an Activity ID however in submit code the
activity attribute was being set the Activity, simply removing this
assignment should fix the issue as everything is set correctly at this point.

I have also moved the creation of the activity above the processing of media
to avoid race conditions.

mediagoblin/submit/lib.py
mediagoblin/user_pages/views.py

index ea24ec5cf5fc45ca0f040f64600b356d1c5886fe..ea05e00fa24dfe363099ec8d7080521a333016f5 100644 (file)
@@ -195,18 +195,18 @@ def submit_media(mg_app, user, submitted_file, filename,
     else:
         feed_url = None
 
+    add_comment_subscription(user, entry)
+
+    # Create activity
+    create_activity("post", entry, entry.uploader)
+    entry.save()
+
     # Pass off to processing
     #
     # (... don't change entry after this point to avoid race
     # conditions with changes to the document via processing code)
     run_process_media(entry, feed_url)
 
-    add_comment_subscription(user, entry)
-
-    # Create activity
-    entry.activity = create_activity("post", entry, entry.uploader).id
-    entry.save()
-
     return entry
 
 
@@ -291,11 +291,11 @@ def api_add_to_feed(request, entry):
         qualified=True, user=request.user.username
     )
 
-    run_process_media(entry, feed_url)
     add_comment_subscription(request.user, entry)
 
     # Create activity
-    entry.activity = create_activity("post", entry, entry.uploader).id
+    create_activity("post", entry, entry.uploader)
     entry.save()
+    run_process_media(entry, feed_url)
 
     return json_response(entry.serialize(request))
index b6cbcabd4d8d07d02870bee697eab5ada577659f..822f359a4b65d2aac633d21a33ab10783368e417 100644 (file)
@@ -195,15 +195,14 @@ def media_post_comment(request, media):
             messages.ERROR,
             _("Oops, your comment was empty."))
     else:
+        create_activity("post", comment, comment.author, target=media)
+        add_comment_subscription(request.user, media)
         comment.save()
 
         messages.add_message(
             request, messages.SUCCESS,
             _('Your comment has been posted!'))
-
         trigger_notification(comment, media, request)
-        create_activity("post", comment, comment.author, target=media)
-        add_comment_subscription(request.user, media)
 
     return redirect_obj(request, media)
 
@@ -263,8 +262,8 @@ def media_collect(request, media):
         collection.description = form.collection_description.data
         collection.creator = request.user.id
         collection.generate_slug()
-        collection.save()
         create_activity("create", collection, collection.creator)
+        collection.save()
 
     # Otherwise, use the collection selected from the drop-down
     else: