From a262bf3ef45d98b316bd9b6f16a06253767ec64f Mon Sep 17 00:00:00 2001 From: Martin Kylian Date: Wed, 19 Mar 2025 20:29:34 +0100 Subject: [PATCH] fix unparse_entry_record - prefer changetype attr as first entry This is a follow up for https://github.com/abilian/ldif/pull/6/commits Released sorting of attribute may cause the "changetype" to get out of expected order. This PR fixes the order and make changetype first in order. --- src/ldif.py | 14 +++++++++++++- 1 file changed, 13 insertions(+), 1 deletion(-) diff --git a/src/ldif.py b/src/ldif.py index 3802001..fc51490 100644 --- a/src/ldif.py +++ b/src/ldif.py @@ -134,11 +134,23 @@ def _unparse_entry_record(self, entry): """ :type entry: Dict[string, List[string]] :param entry: Dictionary holding an entry + + Process "changetype" attribute first if it exists and then rest of attributes """ - for attr_type in entry.keys(): + keys = list(entry.keys()) + + for attr_type in keys: + if isinstance(attr_type, str) and "changetype" in attr_type.lower(): + for attr_value in entry[attr_type]: + self._unparse_attr("changetype", attr_value) + + for attr_type in keys: + if attr_type.lower() == "changetype": + continue for attr_value in entry[attr_type]: self._unparse_attr(attr_type, attr_value) + def _unparse_changetype(self, mod_len): """Detect and write the changetype.""" if mod_len == 2: