misc: do not update Issuer uselessly (#86976)
gitea/django-mellon/pipeline/head This commit looks good Details

This commit is contained in:
Benjamin Dauvergne 2024-02-14 18:19:32 +01:00
parent b372884c2d
commit 7f58bf9c66
1 changed files with 8 additions and 2 deletions

View File

@ -19,12 +19,18 @@ from . import models, utils
def get_issuer(entity_id):
idp = utils.get_idp(entity_id)
slug = idp.get('SLUG')
issuer = None
if slug:
issuer = models.Issuer.objects.filter(slug=slug).first()
# migrate issuer entity_id based on the slug
if issuer and issuer.entity_id != entity_id:
issuer.entity_id = entity_id
issuer.save()
if not slug or not issuer:
issuer, _ = models.Issuer.objects.update_or_create(entity_id=entity_id, defaults={'slug': slug})
if issuer is None:
issuer, _ = models.Issuer.objects.get_or_create(entity_id=entity_id)
# migrate issuer slug based on the entity_id
if issuer.slug != slug:
issuer.slug = slug
issuer.save()
return issuer