From a6b16ecc68f72eeb9d68f3312ed153939184a837 Mon Sep 17 00:00:00 2001 From: Jens L Date: Tue, 16 May 2023 22:17:56 +0200 Subject: [PATCH] =?UTF-8?q?lib:=20fix=20fallback=5Fnames=20migration=20not?= =?UTF-8?q?=20working=20when=20multiple=20objects=20n=E2=80=A6=20(#5637)?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit lib: fix fallback_names migration not working when multiple objects need to be renamed Signed-off-by: Jens Langhammer --- authentik/lib/migrations.py | 10 +++++++++- 1 file changed, 9 insertions(+), 1 deletion(-) diff --git a/authentik/lib/migrations.py b/authentik/lib/migrations.py index 39e627ecf..9239430e6 100644 --- a/authentik/lib/migrations.py +++ b/authentik/lib/migrations.py @@ -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()