Fix deleting integrations with duplicate names (#3397)

# What this PR does

Fixes a bug when it's not possible to delete two or more integrations
having the same name at once.

## Which issue(s) this PR fixes

https://github.com/grafana/oncall-private/issues/2313

## 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)
This commit is contained in:
Vadim Stepanov 2023-11-21 12:44:21 +00:00 committed by GitHub
parent d2c9e2743c
commit cb2d4fa76b
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
4 changed files with 30 additions and 8 deletions

View file

@ -7,6 +7,10 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
## Unreleased
### Fixed
- Fix deleting integrations with duplicate names by @vadimkerr ([#3397](https://github.com/grafana/oncall/pull/3397))
## v1.3.60 (2023-11-20)
### Fixed

View file

@ -0,0 +1,17 @@
# Generated by Django 4.2.7 on 2023-11-21 12:25
from django.db import migrations
class Migration(migrations.Migration):
dependencies = [
('alerts', '0038_remove_alertgroup_is_restricted_db'),
]
operations = [
migrations.RemoveConstraint(
model_name='alertreceivechannel',
name='unique integration name',
),
]

View file

@ -206,14 +206,6 @@ class AlertReceiveChannel(IntegrationOptionsMixin, MaintainableObject):
rate_limited_in_slack_at = models.DateTimeField(null=True, default=None)
rate_limit_message_task_id = models.CharField(max_length=100, null=True, default=None)
class Meta:
constraints = [
models.UniqueConstraint(
fields=["organization", "verbal_name", "deleted_at"],
name="unique integration name",
)
]
def __str__(self):
short_name_with_emojis = emojize(self.short_name, language="alias")
return f"{self.pk}: {short_name_with_emojis}"

View file

@ -220,3 +220,12 @@ def test_alertmanager_available_for_heartbeat(make_organization, make_alert_rece
organization = make_organization()
alert_receive_channel = make_alert_receive_channel(organization, integration=integration)
assert alert_receive_channel.is_available_for_integration_heartbeat
@pytest.mark.django_db
def test_delete_duplicate_names(make_organization, make_alert_receive_channel):
"""Check that it's possible to delete two integrations with the same name at once."""
organization = make_organization()
for _ in range(2):
make_alert_receive_channel(organization, verbal_name="duplicate")
organization.alert_receive_channels.all().delete()