lib: fix fallback_names migration not working when multiple objects n… (#5637)

lib: fix fallback_names migration not working when multiple objects need to be renamed

Signed-off-by: Jens Langhammer <jens@goauthentik.io>
This commit is contained in:
Jens L 2023-05-16 22:17:56 +02:00 committed by GitHub
parent a41924939b
commit a6b16ecc68
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23

View file

@ -19,7 +19,15 @@ def fallback_names(app: str, model: str, field: str):
if value not in seen_names:
seen_names.append(value)
continue
new_value = value + "_2"
separator = "_"
suffix_index = 2
while (
klass.objects.using(db_alias)
.filter(**{field: f"{value}{separator}{suffix_index}"})
.exists()
):
suffix_index += 1
new_value = f"{value}{separator}{suffix_index}"
setattr(obj, field, new_value)
obj.save()