[Mailman-Developers] REST API delete user function does not delete every 2nd linked address
Barry Warsaw
barry at list.org
Mon Feb 9 00:52:51 CET 2015
On Feb 09, 2015, at 07:06 AM, Andrew Stuart wrote:
>This appears to fix the problme in rest/users.py
>
> def on_delete(self, request, response):
> """Delete the named user, all her memberships, and addresses."""
> if self._user is None:
> not_found(response)
> return
> for member in self._user.memberships.members:
> member.unsubscribe()
> user_manager = getUtility(IUserManager)
> addresses_for_deletion = []
> for address in self._user.addresses:
> # to avoid mutating the self._user.addresses iterator, create a separate list of addresses
> addresses_for_deletion.append(address)
> for address in addresses_for_deletion:
> user_manager.delete_address(address)
> user_manager.delete_user(self._user)
> no_content(response)
Thanks for tracking this down. I don't know whether this may have changed
between Storm and SQLAlchemy, but it's very likely at least now caused by the
old mutate-dictionary-while-iterating problem. With the switch to Python 3,
if it were a dictionary an exception would have been thrown:
Python 3.4.2 (default, Feb 3 2015, 14:26:38)
[GCC 4.9.2] on linux
Type "help", "copyright", "credits" or "license" for more information.
>>> d = dict(a=1, b=2, c=3, d=4)
>>> for k in d:
... del d[k]
...
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
RuntimeError: dictionary changed size during iteration
>>>
Thanks for opening the bug; I'll work up a test case and a fix, but I think
you're in the right direction.
Cheers,
-Barry
More information about the Mailman-Developers
mailing list