Opened 10 years ago

Closed 10 years ago

Last modified 10 years ago

#1017 closed defect (fixed)

Key (activity)=(n) is not present in table "core__activity_intermediators".

Reported by: ayleph Owned by:
Priority: major Milestone:
Component: programming Keywords: activity, db, models, foreignkey
Cc: Parent Tickets:

Description

Running from current git master https://gitorious.org/mediagoblin/mediagoblin/commit/c5f258fec07b9791b35d52298dd71954de81ef20, I get an error when a user uploads media. The file is uploaded, but the user gets a SERVER ERROR page, and I get entries in my logfile.

Here's one such example.

IntegrityError: (IntegrityError) insert or update on table "core__media_entries" violates foreign key constraint "core__media_entries_activity_fkey"
DETAIL:  Key (activity)=(1025) is not present in table "core__activity_intermediators".
 'UPDATE core__media_entries SET activity=%(activity)s WHERE core__media_entries.id = %(core__media_entries_id)s' {'core__media_entries_id': 1278, 'activity': 1025}

If I query the db directly, I see that activity 1025 indeed does not exist.

mediagoblin=# select * from core__activity_intermediators where id > 1010;
  id  |    type
------+------------
 1011 | media
 1012 | media
 1013 | media
 1014 | media
 1015 | media
 1016 | media
 1017 | media
 1018 | media
 1019 | media
 1020 | media
(10 rows)

And if I examine the media entry that was created, I see that its activity id is 1020 (the last id number in the activity intermediators table), not 1025.

mediagoblin=# select * from core__media_entries where id = 1278;
  id  | uploader | title |    slug    |          created           | description |          media_type           |   state   |                   license                   | file_size | fail_error | fail_metadata | transcoding_pr
ogress | queued_media_file |            queued_task_id            | media_metadata | activity | location
------+----------+-------+------------+----------------------------+-------------+-------------------------------+-----------+---------------------------------------------+-----------+------------+---------------+---------------
-------+-------------------+--------------------------------------+----------------+----------+----------
 1278 |        3 |       | tucker12-2 | 2014-10-28 21:13:19.904526 |             | mediagoblin.media_types.image | processed | http://creativecommons.org/licenses/by/3.0/ |         0 |            |               |
       |                   | 3cb0017d-5539-4e78-9b7a-25a4a2e3dce7 | {}             |     1020 |
(1 row)

Perhaps this is related to #984?

Change History (3)

comment:1 by Jessica Tallon, 10 years ago

Owner: set to Jessica Tallon
Status: newin_progress

This was caused by:

mediagoblin/submit/lib.py:206-209

 # Create activity
 entry.activity = create_activity("post", entry, entry.uploader).id
 entry.save()

create_activity is returning an Activity object, this then tries to assign the Activity.id to the entry.activity foreign key which actually should (and does at this point) contain the ID to the ActivityIntermediatory not Activity. Trying to set this ForeignKey to another model rightly causes an IntegrityError.

The simple fix is to remove the assignment as all the objects contain the correct values at this point. I have corrected this in commit bc2c06a, along with moving the code above the run_process_media task to avoid the race conditions that a comment a view lines up wisely warns about.

Please test again with the fix to ensure everything is working as it should.

comment:2 by Jessica Tallon, 10 years ago

Owner: Jessica Tallon removed
Resolution: fixed
Status: in_progressclosed

comment:3 by ayleph, 10 years ago

Tsyesika and I were collaborating on IRC for this one. I confirmed that the fix posted above solved the issue.

Note: See TracTickets for help on using tickets.