oncall-engine/engine/apps/schedules
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
..
ical_events Do not include event repetitions terminated before start (until rrule) 2022-11-30 08:56:19 -03:00
migrations Fix Grafana teams sync (#1652) 2023-03-28 18:26:24 +00:00
models Fix Grafana teams sync (#1652) 2023-03-28 18:26:24 +00:00
tasks Matiasb/fix task refresh ical when empty value (#1401) 2023-02-24 21:16:09 +00:00
tests Fix Grafana teams sync (#1652) 2023-03-28 18:26:24 +00:00
__init__.py World, meet OnCall! 2022-06-03 08:09:47 -06:00
admin.py World, meet OnCall! 2022-06-03 08:09:47 -06:00
constants.py Schedules alpha fixes (#541) 2022-09-21 11:19:59 +01:00
ical_utils.py Fix load of ical file from google (#1381) 2023-02-22 07:29:59 +01:00