Alias_method -> endless loop between plugins

Added by Guillaume DUPE 5 months ago

Hello everyone,

I'm trying to update redmine and all the plugins I use to the lastest version (3.4.6 -> 4.0.5).
I finish to upgrade all the plugins and redmine but, I discover an error not so easy (I think).
I have a backlog plugins which use alias_method like this:

alias_method :available_filters_without_backlogs_issue_type, :available_filters
alias_method :available_filters, :available_filters_with_backlogs_issue_type

Endless loop step:
  • So this plugin (backlogs) has a method available_filters_with_backlogs_issue_type which call available_filters_without_backlogs_issue_type and add some information after. (All is normal here)
  • When available_filters_without_backlogs_issue_type is called, it is redirected to the available_filters method of another plugin name workflow_hidden_fields.
  • And this plugins call the super method of this mehod (available_filters) which have for only one match available_filters_with_backlogs_issue_type method of the backlogs plugins.
    It is this repeat again and again and again and ag...

I don't have the permission to edit the core (redmine), I can only change the plugins.

Why isn't an easy problem ?
- I think a can't change the alias_method of backlogs because backlog is an overlay which include all the plugins so the core need to call only him.
- I can't change the name "available_filters" of workflow_hidden_fields because, if i do this, the super doesn't work.

I have wrong ?

Backlog:
def available_filters_with_backlogs_issue_type
@available_filters = available_filters_without_backlogs_issue_type
return @available_filters if !show_backlogs_issue_items?(project)
....
end

Workflow_hidden_field:
def available_filters
unless @available_filters
@available_filters = super
....
end
@available_filters
end

I search how to delete alias_method when the method available_filters_with_backlogs_issue_type is called (remove_alias) but no one works (undefined method).

I learn ruby on rails since one month.

Sorry for my english.

Thanks a lot,

Have a good day !

Guillaume

Replies (1)

RE: Alias_method -> endless loop between plugins - Added by Jérôme BATAILLE 2 months ago

Hi, you can reliably replace alias_method by prepending the modules and calling super in the overridden method.

This is quite simpler and cleaner.

You just have to add your method in the Module without with... postfix
And in your init.rb :

IssueQuery.send(:prepend Backlogs::IssueQueryPatch) unless IssueQuery.included_modules.include? Backlogs::IssueQueryPatch

P.S. this does not work for Helpers.

(1-1/1)