From 69b565e1adb00bb34b9de7ecdd6b988062c23ed5 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=C3=89loi=20Rivard?= Date: Sun, 28 Apr 2024 16:18:24 +0200 Subject: [PATCH] refactor: LDAP backend tolerates double deletions --- canaille/backends/ldap/ldapobject.py | 5 ++++- tests/backends/test_models.py | 2 ++ 2 files changed, 6 insertions(+), 1 deletion(-) diff --git a/canaille/backends/ldap/ldapobject.py b/canaille/backends/ldap/ldapobject.py index 4bbbd155..da837b25 100644 --- a/canaille/backends/ldap/ldapobject.py +++ b/canaille/backends/ldap/ldapobject.py @@ -477,4 +477,7 @@ def save(self): def delete(self): conn = Backend.get().connection - conn.delete_s(self.dn) + try: + conn.delete_s(self.dn) + except ldap.NO_SUCH_OBJECT: + pass diff --git a/tests/backends/test_models.py b/tests/backends/test_models.py index 02fb75a1..02b3d0ff 100644 --- a/tests/backends/test_models.py +++ b/tests/backends/test_models.py @@ -61,6 +61,8 @@ def test_model_lifecycle(testclient, backend): assert not models.User.query(id=user.id) assert not models.User.get(id=user.id) + user.delete() + def test_model_attribute_edition(testclient, backend): user = models.User(