# 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) |
||
|---|---|---|
| .. | ||
| api_helpers | ||
| constants | ||
| custom_celery_tasks | ||
| exceptions | ||
| insight_log | ||
| jinja_templater | ||
| oncall_gateway | ||
| recaptcha | ||
| tests | ||
| __init__.py | ||
| admin.py | ||
| database.py | ||
| public_primary_keys.py | ||
| timezones.py | ||
| utils.py | ||