[traceback] IntegrityError: (1451, 'Cannot delete or update a parent row: a foreign key constraint fails

VERIFIED FIXED in 2014-01-07

Status

P3
normal
VERIFIED FIXED
5 years ago
5 years ago

People

(Reporter: eviljeff, Assigned: mat)

Tracking

2014-01-07
Points:
---

Details

(Whiteboard: [incorrect_implementation])

IntegrityError: (1451, 'Cannot delete or update a parent row: a foreign key constraint fails (`addons_mozilla_org`.`log_activity_version_mkt`, CONSTRAINT `version_id_refs_id_e1ef9328` FOREIGN KEY (`version_id`) REFERENCES `versions` (`id`))')

Stacktrace (most recent call last):

  File "django/core/handlers/base.py", line 111, in get_response
    response = callback(request, *callback_args, **callback_kwargs)
  File "amo/decorators.py", line 157, in wrapper
    return f(*args, **kw)
  File "amo/decorators.py", line 149, in wrapper
    return f(*args, **kw)
  File "addons/decorators.py", line 33, in wrapper
    return f(request, addon, *args, **kw)
  File "amo/decorators.py", line 32, in wrapper
    return func(request, *args, **kw)
  File "mkt/developers/decorators.py", line 49, in wrapper
    return fun()
  File "mkt/developers/decorators.py", line 28, in <lambda>
    *args, **kw)
  File "amo/decorators.py", line 51, in wrapper
    return f(request, *args, **kw)
  File "mkt/developers/views.py", line 158, in delete
    addon.delete(msg='Removed via devhub', reason=reason)
  File "django/db/transaction.py", line 224, in inner
    return func(*args, **kwargs)
  File "addons/models.py", line 440, in delete
    super(Addon, self).delete()
  File "django/db/models/base.py", line 576, in delete
    collector.delete()
  File "django/db/models/deletion.py", line 61, in decorated
    func(self, *args, **kwargs)
  File "django/db/models/deletion.py", line 263, in delete
    query.delete_batch(pk_list, self.using)
  File "django/db/models/sql/subqueries.py", line 44, in delete_batch
    self.do_query(self.model._meta.db_table, where, using=using)
  File "django/db/models/sql/subqueries.py", line 29, in do_query
    self.get_compiler(using).execute_sql(None)
  File "django/db/models/sql/compiler.py", line 818, in execute_sql
    cursor.execute(sql, params)
  File "django/db/backends/mysql/base.py", line 114, in execute
    return self.cursor.execute(query, args)
  File "MySQLdb/cursors.py", line 173, in execute
    self.errorhandler(self, exc, value)
  File "MySQLdb/connections.py", line 36, in defaulterrorhandler
    raise errorclass, errorvalue
Target Milestone: --- → 2013-11-26
Assignee: nobody → mpillard
Priority: -- → P3
Pretty sure I made these cascade on delete a long time ago... hm...
(Assignee)

Updated

5 years ago
Target Milestone: 2013-11-26 → ---
(Assignee)

Comment 3

5 years ago
Here is what's happening:

- This app has status 0 - incomplete
- It also has two *deleted* versions
- Because it has status 0, we do a real delete instead of a soft-delete
- Django tries to delete associated versions before deleting the addon row. There are some versions, but their default manager is saying they don't exist because they are deleted, so it doesn't find them
- It sends the query to delete the addon to MySQL, which complains there are still some versions rows linking to this app

This doesn't happen on AMO because only Marketplace soft-deletes versions.
(Assignee)

Updated

5 years ago
Status: NEW → ASSIGNED
(Assignee)

Updated

5 years ago
Target Milestone: --- → 2014-01-07
(Assignee)

Comment 4

5 years ago
Fixed in https://github.com/mozilla/zamboni/commit/03efb4b8d62c4332189b178ad0e2f31f899106eb

STR:
- Submit a packaged app
- Upload a first version
- Upload a second version
- Delete both versions
- The app should now be incomplete. Try deleting the app.

Expected:
- It should work just fine. 

Actual:
- It gives you an internal server error


In addition, please make sure that you can submit an app using the same app slug you were using with the app you just deleted (i.e. re-start the submit process with the same .zip)
Status: ASSIGNED → RESOLVED
Last Resolved: 5 years ago
Resolution: --- → FIXED

Comment 5

5 years ago
Verified as fixed in https://marketplace-dev.allizom.org/developers/ on FF29 (Win 7).
Postfix screencast http://screencast.com/t/oJRuL9xz
Closing bug.
Status: RESOLVED → VERIFIED

Updated

5 years ago
Whiteboard: [incorrect_implementation]
You need to log in before you can comment on or make changes to this bug.