fix(leads): reactivate archived tags named in a CSV import

This commit is contained in:
moneebullah25 2026-10-10 11:12:33 -04:00
parent 5d71f26368
commit bc251bbd6c
2 changed files with 14 additions and 3 deletions

View file

@ -397,7 +397,10 @@ def _get_or_create_tag(name: str, org, cache: dict[str, Tags]) -> Tags:
# SELECT-then-INSERT race when two imports name the same new tag.
slug = Tags.slug_for(name)
if slug not in cache:
cache[slug], _ = Tags.objects.get_or_create(
slug=slug, org=org, defaults={"name": name}
)
tag, _ = Tags.objects.get_or_create(slug=slug, org=org, defaults={"name": name})
if not tag.is_active:
# Same as the tags API: naming an archived tag brings it back.
tag.is_active = True
tag.save(update_fields=["is_active"])
cache[slug] = tag
return cache[slug]

View file

@ -591,3 +591,11 @@ class TestTagSlugs:
tag = Tags.objects.get(org=org_a)
assert tag.slug == "trade-show"
assert set(Lead.objects.values_list("tags", flat=True)) == {tag.id}
def test_archived_tag_is_reactivated(self, admin_client, org_a):
Tags.objects.create(name="VIP", slug="vip", org=org_a, is_active=False)
response = _post(admin_client, COMMIT, self._tagged("a@example.com", "VIP"))
assert response.status_code == 200, response.json()
tag = Lead.objects.get().tags.get()
assert tag.is_active
assert Tags.objects.filter(org=org_a).count() == 1