oncall-engine/engine/apps
Vadim Stepanov 3c00345f54
Fix Grafana teams sync (#1652)
# What this PR does
Sometimes plugin sync fails with the following exception:
```
Cannot delete or update a parent row: a foreign key constraint fails (`schedules_oncallschedule`, CONSTRAINT `alerts_oncallschedul_team_id_4e633f4b_fk_user_mana` FOREIGN KEY (`team_id`) REFERENCES `user_management_team` (`id`))'
```

How to reproduce:
1. Create a new Grafana team
2. Create two schedules with different types (e.g. ICal and Web) and
assign both schedules to the new team
3. Delete the team in Grafana
4. Trigger plugin sync, the sync will fail with the exception above

This happens because the `OnCallSchedule` Django model is a polymorphic
model and there's a [known
bug](https://github.com/django-polymorphic/django-polymorphic/issues/229)
in `django-polymorphic` with deleting related objects when using
`SET_NULL` and `CASCADE`. This PR adds non-polymorphic versions of
`SET_NULL` and `CASCADE` to use in schedule FKs as per this
[comment](https://github.com/django-polymorphic/django-polymorphic/issues/229#issuecomment-398434412).

This also applies to two other schedule FKs: `organization` and
`user_group`, which are not working properly as well.

## Checklist

- [x] Unit, integration, and e2e (if applicable) tests updated
- [x] Documentation added (or `pr:no public docs` PR label added if not
required)
- [x] `CHANGELOG.md` updated (or `pr:no changelog` PR label added if not
required)
2023-03-28 18:26:24 +00:00
..
alerts Teams redesign (#1528) 2023-03-22 00:57:20 +08:00
api Improve schedule quality feature (#1602) 2023-03-27 11:03:16 +00:00
api_for_grafana_incident Include alert details in Grafana Incident alert-group endpoint (#1280) 2023-02-03 13:43:21 +00:00
auth_token Change Organization Deleted/Moved Precedence (#1402) 2023-02-24 11:45:21 +00:00
base Inbound email integration (#837) 2023-03-16 13:59:21 +08:00
email Inbound email integration (#837) 2023-03-16 13:59:21 +08:00
grafana_plugin Check stack cluster for insight_logs (#1469) 2023-03-09 06:30:54 +00:00
heartbeat Add database migrations linter (#1020) 2023-02-06 16:01:37 +08:00
integrations Inbound email integration (#837) 2023-03-16 13:59:21 +08:00
mobile_app Update apns payload with corrected critical field (#1646) 2023-03-28 10:57:40 +00:00
oss_installation Add database migrations linter (#1020) 2023-02-06 16:01:37 +08:00
public_api Teams redesign (#1528) 2023-03-22 00:57:20 +08:00
schedules Fix Grafana teams sync (#1652) 2023-03-28 18:26:24 +00:00
slack Slack team connector v2 (#1581) 2023-03-28 03:27:45 +00:00
social_auth Slack team connector v2 (#1581) 2023-03-28 03:27:45 +00:00
telegram Refactor get_user_verbal_for_team_for_slack. (#809) 2023-03-07 10:09:37 +00:00
twilioapp Add database migrations linter (#1020) 2023-02-06 16:01:37 +08:00
user_management Fix Grafana teams sync (#1652) 2023-03-28 18:26:24 +00:00
webhooks Keep webhook responses data (#1580) 2023-03-21 13:43:37 +00:00
__init__.py World, meet OnCall! 2022-06-03 08:09:47 -06:00