oncall-engine/engine/common
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
..
api_helpers use CustomURLValidator in custom_button (#1398) 2023-03-23 12:21:17 +00:00
constants Add RBAC Support (#777) 2022-11-29 09:41:56 +01:00
custom_celery_tasks World, meet OnCall! 2022-06-03 08:09:47 -06:00
exceptions Remove auto-recreating logic for UserNotificationPolicy (#414) 2022-08-26 13:46:50 +05:00
insight_log Check stack cluster for insight_logs (#1469) 2023-03-09 06:30:54 +00:00
jinja_templater Add regex_match Jinja filter (#1556) 2023-03-16 10:18:49 +00:00
oncall_gateway Slack team connector v2 (#1581) 2023-03-28 03:27:45 +00:00
recaptcha Add validation of hostname for recapctha (#1445) 2023-03-06 08:59:48 +00:00
tests use CustomURLValidator in custom_button (#1398) 2023-03-23 12:21:17 +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
database.py Fix Grafana teams sync (#1652) 2023-03-28 18:26:24 +00:00
public_primary_keys.py Insight logs (#348) 2022-08-24 12:04:44 +05:00
timezones.py centralize timezone validation + add serializer validation for on call shifts and schedules (#924) 2022-12-01 14:13:39 +01:00
utils.py Set DATA_UPLOAD_MAX_MEMORY_SIZE to 1mb (#393) 2022-08-24 11:59:01 +05:00