Deleting a user via the REST API does not delete their user preferences

Bug #1418276 reported by Andrew Stuart on 2015-02-05
8
This bug affects 1 person
Affects Status Importance Assigned to Milestone
GNU Mailman
High
Abhishek

Bug Description

The on_delete function in rest/users.py appears to not delete user preferences when the user is deleted resulting in an accumulation of orphaned preferences data.

    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)
        for address in self._user.addresses:
            user_manager.delete_address(address)
        user_manager.delete_user(self._user)
        no_content(response)

Barry Warsaw (barry) on 2015-02-05
tags: added: mailman3
Changed in mailman:
assignee: nobody → Ankush Sharma (black-perl)
Abhishek (abhi170893) on 2015-03-15
Changed in mailman:
assignee: Ankush Sharma (black-perl) → Abhishek (abhi170893)
Abhishek (abhi170893) wrote :

Deleted the preferences of the user being deleted before deleting him.

Changed in mailman:
status: New → In Progress
Abhishek (abhi170893) wrote :

Deleted the preferences of the user being deleted before deleting him and added test for it.

Barry Warsaw (barry) wrote :

Thanks for the patch and the test, it's a great contribution. I am going to apply it with some modifications. Here is some feedback for the future:

Please read PEP 8 and the Mailman style guide for our coding standards.

Because the fix is in the model, there should be a test in the model. It's okay to also have a test in the REST layer because that's where the problem was observed. I adapted your REST test and added one to the model.

Be sure to run the full test suite with `tox` both before and after applying your fix. It's a good idea to add the test, run tox to validate that the test fails, then add your fix to validate that it succeeds. Also, running the full suite before submitting a patch ensures that there are no regressions elsewhere in Mailman.

When attributing fixes by community members, I use the name given in your Launchpad id. If you want your full name to appear in the NEWS file, please contact me directly.

See r7307 for the full, applied patch.

Changed in mailman:
milestone: none → 3.0.0b6
importance: Undecided → High
status: In Progress → Fix Committed
Abhishek (abhi170893) wrote :

Thanks Barry for the suggestions. I will see the PEP 8 and the Mailman guide. And i tried pushing the branch for the merge proposal, but from inside the college i cant do ssh outside and was getting error. So i submitted the patch.

I looked at the r7307 and wanted to ask something:

In rest/tests/test_users.py you have used config.db.store.query(Preferences) inside with. But there is another usage of it in line 221 and also in the file model/tests/test_user.py which are not inside with block. Any specific reason for the difference..?

230 with transaction():
231 preferences = config.db.store.query(Preferences).filter_by(
232 id=anne.preferences.id)
233 self.assertEqual(preferences.count(), 0)

On Mar 20, 2015, at 05:41 PM, Abhishek wrote:

>In rest/tests/test_users.py you have used
>config.db.store.query(Preferences) inside with. But there is another
>usage of it in line 221 and also in the file model/tests/test_user.py
>which are not inside with block. Any specific reason for the
>difference..?
>
>230 with transaction():
>231 preferences = config.db.store.query(Preferences).filter_by(
>232 id=anne.preferences.id)
>233 self.assertEqual(preferences.count(), 0)

Yes. The ids don't get assigned until after the commit, so they have to be
within the with-statement in order for the subsequent query to work. But
after that, the delete does not require a commit for the query to succeed.

I don't think this was the case with Storm, but it appears to be so with
SQLAlchemy.

Barry Warsaw (barry) on 2015-04-28
Changed in mailman:
status: Fix Committed → Fix Released
To post a comment you must log in.
This report contains Public information  Edit
Everyone can see this information.

Other bug subscribers