Page MenuHomePhabricator

It is not possible to delete a ticket with several notifications
Closed, ResolvedPublic

Description

It fails with this error

IntegrityError: (1451, 'Cannot delete or update a parent row: a foreign key constraint fails (`tracker_main`.`tracker_notification`, CONSTRAINT `tracker_notifica_ticket_id_59e3495a9a2568da_fk_tracker_ticket_id` FOREIGN KEY (`ticket_id`) REFERENCES `tracker_ticket` (`id`))')

This is from ticket with notifications. It wasn't possible to delete the ticket even after manually purging the notifications (by running DELETE FROM tracker_notification WHERE ticket_id=1596; in SQL console) and restarting Uwsgi (by running touch deploy/reload), with the same error.

I tried to reproduce the same situation on tracker2 (test setup), by doing the following:

  1. Create test user, with email address.
  2. Add that test user as an admin to a topic
  3. Under other account I created a ticket in that topic
  4. I checked in DB, if notifications were scheduled, they were
  5. I tried to delete the ticket via admin interface
  6. I was warned that it will delete Notification object as well.
  7. The ticket deleted successfully

The test server was running f7394b9, production server was running e1b0bdb3f2cb02a33c0d37d830a6132dc5e88591, but it was working like above even after upgrading.

However, when I tried to add some acks between step 3 and 4 to have other notification objects created, I got the above error while deleting.

I also tried to create a ticket in topic with more than one administrator (so more than one notification of same type is issued). There were no problems with it.

I tried to delete the test ticket again after notifications were distributed (by regular daily digest, I did not force it), it failed with the following error.

IntegrityError: (1451, 'Cannot delete or update a parent row: a foreign key constraint fails (`tracker_test`.`tracker_notification`, CONSTRAINT `tracker_notifica_ticket_id_59e3495a9a2568da_fk_tracker_ticket_id` FOREIGN KEY (`ticket_id`) REFERENCES `tracker_ticket` (`id`))')

Conclusion: it is not possible to delete a tiket that caused notification about at least two events using Django internal mechanism.

When I tried to do DELETE FROM tracker_ticket WHERE id=1596, it succeeded on my first try.

Event Timeline

Urbanecm triaged this task as Unbreak Now! priority.Sep 19 2018, 4:13 PM
Urbanecm renamed this task from It is not possible to delete a tiket with one or more notification to It is not possible to delete a tiket with several notifications.Sep 19 2018, 4:58 PM
Urbanecm updated the task description. (Show Details)
Schniggendiller renamed this task from It is not possible to delete a tiket with several notifications to It is not possible to delete a ticket with several notifications.Sep 19 2018, 8:10 PM

Change 462741 had a related patch set uploaded (by Urbanecm; owner: Urbanecm):
[wikimedia-cz/tracker@master] Get rid of ticket foreign key in Notification object

https://gerrit.wikimedia.org/r/462741

Change 462741 merged by jenkins-bot:
[wikimedia-cz/tracker@master] Get rid of ticket foreign key in Notification object

https://gerrit.wikimedia.org/r/462741