"Address already exists" when creating a new user, but user is created anyway

Bug #1418280 reported by Andrew Stuart
6
This bug affects 1 person
Affects Status Importance Assigned to Milestone
GNU Mailman
Fix Released
High
Barry Warsaw

Bug Description

When creating a new user via the REST API, if the email address exists, it reports "Address already exists", but it creates the user anyway.

After a bit of deep cave diving into the code I suspect it’s this in model/usermanager.py

This function appears to create a user before it checks to see if the address exists, with the result that multiple users are created when the address already exists.

@implementer(IUserManager)
class UserManager:
   """See `IUserManager`."""

   def create_user(self, email=None, display_name=None):
       """See `IUserManager`."""
       user = User(display_name, Preferences())
       if email:
           address = self.create_address(email, display_name)
           user.link(address)
       return user

this seems to fix the problem - but please don’t trust my solution - needs verification.

@implementer(IUserManager)
class UserManager:
   """See `IUserManager`."""

   def create_user(self, email=None, display_name=None):
       """See `IUserManager`."""
       if email:
           address = self.create_address(email, display_name)
       user = User(display_name, Preferences())
       if email:
           user.link(address)
       return user

Tags: mailman3
Barry Warsaw (barry)
tags: added: mailman3
Revision history for this message
Barry Warsaw (barry) wrote :

Your diagnosis and remedy is spot on! I will commit this fix with tests.

Changed in mailman:
status: New → Confirmed
importance: Undecided → High
assignee: nobody → Barry Warsaw (barry)
milestone: none → 3.0.0b6
status: Confirmed → In Progress
Barry Warsaw (barry)
Changed in mailman:
status: In Progress → Fix Committed
Barry Warsaw (barry)
Changed in mailman:
status: Fix Committed → Fix Released
To post a comment you must log in.
This report contains Public information  
Everyone can see this information.

Other bug subscribers

Remote bug watches

Bug watches keep track of this bug in other bug trackers.