diff --git a/authentik/lib/merge.py b/authentik/lib/merge.py new file mode 100644 index 000000000..99a6dab66 --- /dev/null +++ b/authentik/lib/merge.py @@ -0,0 +1,6 @@ +"""merge utils""" +from deepmerge import Merger + +MERGE_LIST_UNIQUE = Merger( + [(list, ["append_unique"]), (dict, ["merge"]), (set, ["union"])], ["override"], ["override"] +) diff --git a/authentik/sources/ldap/sync/base.py b/authentik/sources/ldap/sync/base.py index e8b9cd36e..16b812a50 100644 --- a/authentik/sources/ldap/sync/base.py +++ b/authentik/sources/ldap/sync/base.py @@ -1,13 +1,13 @@ """Sync LDAP Users and groups into authentik""" from typing import Any -from deepmerge import always_merger from django.db.models.base import Model from django.db.models.query import QuerySet from structlog.stdlib import BoundLogger, get_logger from authentik.core.exceptions import PropertyMappingExpressionException from authentik.events.models import Event, EventAction +from authentik.lib.merge import MERGE_LIST_UNIQUE from authentik.sources.ldap.auth import LDAP_DISTINGUISHED_NAME from authentik.sources.ldap.models import LDAPPropertyMapping, LDAPSource @@ -123,8 +123,8 @@ class BaseLDAPSynchronizer: continue setattr(instance, key, value) final_atttributes = {} - always_merger.merge(final_atttributes, instance.attributes) - always_merger.merge(final_atttributes, data.get("attributes", {})) + MERGE_LIST_UNIQUE.merge(final_atttributes, instance.attributes) + MERGE_LIST_UNIQUE.merge(final_atttributes, data.get("attributes", {})) instance.attributes = final_atttributes instance.save() return (instance, False)