oncall-engine/engine/apps
Vadim Stepanov eada4a4355
Fix duplicate orders for user notification policies (#2278)
# What this PR does

Fixes an issue when multiple user notification policies have duplicated
order values, leading to the following unexpected behaviours:
1. Not possible to rearrange notification policies that have duplicated
orders.
2. The notification system only executes the first policy from each
order group. For example, if there are policies with orders `[0, 0, 0,
0]`, only the first policy will be executed, and all others will be
skipped. So the user will see four policies in the UI, while only one of
them will be actually executed.

This PR fixes the issue by adding a unique index on `(user_id,
important, order)` for `UserNotificationPolicy` model. However, it's not
possible to add that unique index using the ordering library that we use
due to it's implementation details.
I added a new abstract Django model `OrderedModel` that's able to work
with such unique indices + under concurrent load.

Important info on this new `OrderedModel` abstract model:
- Orders are unique on the DB level
- Orders are allowed to be non-consecutive, for example order sequence
`[100, 150, 400]` is valid
- When deleting an instance, orders of other instances don't change.
This is a notable difference from the library we use. I think it's
better to only delete the instance without changing any other orders,
because it reduces the number of dependencies between instances (e.g.
Terraform drift will be much smaller this way if a policy is deleted via
the web UI).

## Which issue(s) this PR fixes

Related to https://github.com/grafana/oncall-private/issues/1680

## 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-06-21 11:13:56 +00:00
..
alerts add is_restricted column to alert_group table (#2289) 2023-06-20 06:20:32 -04:00
api Fix duplicate orders for user notification policies (#2278) 2023-06-21 11:13:56 +00:00
api_for_grafana_incident add mypy static type checker to backend codebase (#2151) 2023-06-12 12:50:33 -04:00
auth_token Improve plugin authentication (#1995) 2023-05-23 16:13:25 +00:00
base Fix duplicate orders for user notification policies (#2278) 2023-06-21 11:13:56 +00:00
email Fix warnings when running backend tests (#2079) 2023-06-06 18:38:00 +00:00
grafana_plugin add mypy static type checker to backend codebase (#2151) 2023-06-12 12:50:33 -04:00
heartbeat Add database migrations linter (#1020) 2023-02-06 16:01:37 +08:00
integrations Fix amv2 2023-06-14 14:43:00 +08:00
metrics_exporter Optimize getting response time for alert groups (#2296) 2023-06-21 08:16:35 +00:00
mobile_app refactor title and subtitle of shift notifications (#2288) 2023-06-20 10:49:13 +00:00
oss_installation Add database migrations linter (#1020) 2023-02-06 16:01:37 +08:00
phone_notifications Better simple phone provider (#2143) 2023-06-09 13:21:38 +08:00
public_api Fix duplicate orders for user notification policies (#2278) 2023-06-21 11:13:56 +00:00
schedules Changed web schedule updates to sync refresh ical (#2279) 2023-06-20 15:01:35 +00:00
slack remove SlackActionRecord model/table (#2201) 2023-06-13 10:56:06 +00:00
social_auth Social auth exception logging (#2041) 2023-06-02 11:20:54 +00:00
telegram add mypy static type checker to backend codebase (#2151) 2023-06-12 12:50:33 -04:00
twilioapp add mypy static type checker to backend codebase (#2151) 2023-06-12 12:50:33 -04:00
user_management add is_restricted column to alert_group table (#2289) 2023-06-20 06:20:32 -04:00
webhooks Add field descriptions for webhooks (#2225) 2023-06-14 08:37:30 -06:00
__init__.py World, meet OnCall! 2022-06-03 08:09:47 -06:00