From 80decc3f710f7e0831aa6e6df357872beabaae93 Mon Sep 17 00:00:00 2001 From: downtownallday Date: Mon, 5 Sep 2022 17:20:41 -0400 Subject: [PATCH] fix python error "cannot pickle 'dict_keys' object" a deep copy of a dictionary with values of type `dict_keys`, required by the underlying ldap3 python3 library, is no longer allowed. they must be a `list` type actual error: Traceback (most recent call last): File "/mailinabox/setup/migrate.py", line 461, in run_miabldap_migrations() File "/mailinabox/setup/migrate.py", line 440, in run_miabldap_migrations raise e File "/mailinabox/setup/migrate.py", line 431, in run_miabldap_migrations migration_func(env) File "/mailinabox/setup/migrate.py", line 249, in migration_miabldap_1 users=m13.create_users(env, conn, ldap, ldap_base, ldap_users_base, ldap_domains_base) File "/mailinabox/setup/migration_13.py", line 137, in create_users dn = add_user(env, ldapconn, ldap_base, ldap_users_base, ldap_domains_base, email, password, privs.split("\n"), totp) File "/mailinabox/setup/migration_13.py", line 90, in add_user ldapconn.add(dn, objectClasses, attrs) File "/usr/lib/python3/dist-packages/ldap3/core/connection.py", line 947, in add _attributes = deepcopy(attributes) # dict could change when adding objectClass values File "/usr/lib/python3.10/copy.py", line 146, in deepcopy y = copier(x, memo) File "/usr/lib/python3.10/copy.py", line 231, in _deepcopy_dict y[deepcopy(key, memo)] = deepcopy(value, memo) File "/usr/lib/python3.10/copy.py", line 161, in deepcopy rv = reductor(4) TypeError: cannot pickle 'dict_keys' object --- setup/migration_13.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/setup/migration_13.py b/setup/migration_13.py index 6a8ae9ca..cf98eb8a 100644 --- a/setup/migration_13.py +++ b/setup/migration_13.py @@ -52,7 +52,7 @@ def add_user(env, ldapconn, search_base, users_base, domains_base, email, passwo for priv in privs: if priv.strip() != '': privs_uniq[priv] = True if len(privs_uniq) > 0: - attrs['mailaccess'] = privs_uniq.keys() + attrs['mailaccess'] = list(privs_uniq.keys()) # Get a common name localpart, domainpart = email.split("@") @@ -238,7 +238,7 @@ def add_permitted_senders_group(ldapconn, users_base, group_base, source, permit ldapconn.add(group_dn, [ "mailGroup" ], { "cn" : gid, "mail" : source, - "member" : permitted_dn.keys(), + "member" : list(permitted_dn.keys()), "description": "Permitted to MAIL FROM this address" }) except ldap3.core.exceptions.LDAPEntryAlreadyExistsResult: