# 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)
14 lines
551 B
INI
14 lines
551 B
INI
[flake8]
|
|
max-line-length = 180
|
|
extend-ignore = F541, E203
|
|
extend-exclude = */migrations/*
|
|
ban-relative-imports = parents
|
|
banned-modules =
|
|
jinja2.Template = Use apply_jinja_template instead
|
|
|
|
[pytest]
|
|
# https://pytest-django.readthedocs.io/en/latest/configuring_django.html#order-of-choosing-settings
|
|
# https://pytest-django.readthedocs.io/en/latest/database.html
|
|
addopts = --no-migrations --color=yes --showlocals
|
|
# https://pytest-django.readthedocs.io/en/latest/faq.html#my-tests-are-not-being-found-why
|
|
python_files = tests.py test_*.py *_tests.py
|