Defect #16795

Member#destroy triggers after_destroy callbacks twice

Added by Islam Azab almost 4 years ago. Updated almost 4 years ago.

Status:ClosedStart date:
Priority:NormalDue date:
Assignee:Jean-Philippe Lang% Done:

0%

Category:Code cleanup/refactoring
Target version:2.5.2
Resolution:Fixed Affected version:

Description

The callback 'after_destroy' for Member is called twice when deleting a member due to the following lines
https://github.com/redmine/redmine/blob/master/app/controllers/members_controller.rb:99
and
https://github.com/redmine/redmine/blob/master/app/models/member_role.rb:42

Associated revisions

Revision 13140
Added by Jean-Philippe Lang almost 4 years ago

Fixed that Member#destroy triggers after_destroy callbacks twice (#16795).

Revision 13142
Added by Toshi MARUYAMA almost 4 years ago

replace tabs to spaces (#16795)

History

#1 Updated by Islam Azab almost 4 years ago

https://github.com/redmine/redmine/blob/master/app/controllers/members_controller.rb

def destroy
    if request.delete? && @member.deletable?
      @member.destroy
    end
    respond_to do |format|
      format.html { redirect_to_settings_in_projects }
      format.js
      format.api {
        if @member.destroyed?
          render_api_ok
        else
          head :unprocessable_entity
        end
      }
    end
  end

https://github.com/redmine/redmine/blob/master/app/models/member_role.rb

  def remove_member_if_empty
    if member.roles.empty?
      member.destroy
    end
  end

#2 Updated by Jean-Philippe Lang almost 4 years ago

  • Subject changed from fixed member deletion to avoid dublicate after_destroy callbacks to Member#destroy triggers after_destroy callbacks twice
  • Category set to Code cleanup/refactoring
  • Status changed from New to Resolved
  • Assignee set to Jean-Philippe Lang
  • Target version set to 2.5.2
  • Resolution set to Fixed

Fixed in r13140, thanks for pointing this out.

#3 Updated by Jean-Philippe Lang almost 4 years ago

  • Status changed from Resolved to Closed

Merged.

Also available in: Atom PDF