Forum: Rails-core (closed, excessive spam) Different order of plugin load_paths in $LOAD_PATHS and Dependencies

402602a60e500e85f2f5dc1ff3648ecb?d=identicon&s=25 Sven Fuchs (Guest)
on 2007-12-09 13:57
(Received via mailing list)
I was just about to submit the following ticket including a patch for
Rails 2.0. But then I noticed that this behaviour hasn't been invented
with the recent refactorings of the plugin loading mechanism but was
already there in Rails 1.2.x:
http://dev.rubyonrails.org/browser/tags/rel_1-2-6/...

Therefor I thought it might make more sense to submit this to the
mailinglist first for discussion.

So, is there a particular reason for this behaviour?


# Different order of plugin load_paths in $LOAD_PATHS and Dependencies

In Rails::Plugin::Loader#add_plugin_load_paths paths are inserted into
$LOAD_PATHS in reverse alphabetical order so that plugins loaded later
will take precedence over plugins loaded earlier. (This has been
described as the intended behaviour here:
http://www.ruby-forum.com/topic/133009)

However these paths are appended to Dependencies.load_paths and
Dependencies.load_once_paths so they will appear in alphabetical order
in these array.

http://dev.rubyonrails.org/browser/tags/rel_2-0-1/...

So in effect if there are two files with the same name in two
different plugins like these ...

/plugins/plugin_a/lib/something.rb
/plugins/plugin_b/lib/something.rb

... require 'something' will load the one with latter file while using
Dependencies constant autoloading will load the former file:

require 'something' # loads /plugins/plugin_b/lib/something.rb (correct)
Something           # loads /plugins/plugin_a/lib/something.rb (wrong)
81b61875e41eaa58887543635d556fca?d=identicon&s=25 Frederick Cheung (Guest)
on 2007-12-09 16:56
(Received via mailing list)
On 9 Dec 2007, at 12:56, Sven Fuchs wrote:

> I was just about to submit the following ticket including a patch for
> Rails 2.0. But then I noticed that this behaviour hasn't been invented
> with the recent refactorings of the plugin loading mechanism but was
> already there in Rails 1.2.x: 
http://dev.rubyonrails.org/browser/tags/rel_1-2-6/...
>
> Therefor I thought it might make more sense to submit this to the
> mailinglist first for discussion.
>
> So, is there a particular reason for this behaviour?
>
In days of old, this meant that 'your' stuff would be top of the list
when your init.rb ran, but that's no longer the case.
Just my opinion, but I wouldn't think you'd ever want to be relying on
a specific load path ordering


Fred
2475563a3ba1da4018af64f964ab45b0?d=identicon&s=25 Chad Woolley (Guest)
on 2007-12-10 21:49
(Received via mailing list)
On Dec 9, 2007 5:56 AM, Sven Fuchs <svenfuchs@artweb-design.de> wrote:
>
>
>
> require 'something' # loads /plugins/plugin_b/lib/something.rb (correct)
> Something           # loads /plugins/plugin_a/lib/something.rb (wrong)
>

Check out the thread recently called 'Are plugins supposed to be
loaded alphabetically?'  We explored this in depth, and I think the
current behavior is correct.  Bottom line, you SHOULDN'T have
identically named files on your load path and depend on load path
order.  If you don't agree with that, it's a separate issue.  I think
I agree with it :)

-- Chad
402602a60e500e85f2f5dc1ff3648ecb?d=identicon&s=25 Sven Fuchs (Guest)
on 2007-12-12 18:45
(Received via mailing list)
Hi Frederick, hi Chad,

thanks for your responses.

No offense, but I think both of you missed the point here.

Am 10.12.2007 um 21:44 schrieb Chad Woolley:
> Check out the thread recently called 'Are plugins supposed to be
> loaded alphabetically?'  We explored this in depth, and I think the
> current behavior is correct.

I even linked to that thread. And no, it doesn't explore this issue.

> Bottom line, you SHOULDN'T have
> identically named files on your load path and depend on load path
> order.

I'm not talking about load path order.

In fact, the current implementation in Plugin::Loader makes sure that
the issue is present no matter in which order plugins are loaded:
plugin load_paths are appended to the end of Dependencies.load_paths,
but unshifted to the front (sort of, you get the point) of
$LOAD_PATHS. (see lines 47-49 in rails/plugin/loader.rb)

Thus, no matter how the load order of two plugins is specified, if you
have two files with the same filenames in your plugin load_paths, the
following statements will load different files:

require "something" # uses $LOAD_PATH
Something.called    # uses Dependencies.load_paths



--
sven fuchs      svenfuchs@artweb-design.de
artweb design    http://www.artweb-design.de
gr├╝nberger 65    + 49 (0) 30 - 47 98 69 96 (phone)
d-10245 berlin    + 49 (0) 171 - 35 20 38 4 (mobile)
2475563a3ba1da4018af64f964ab45b0?d=identicon&s=25 Chad Woolley (Guest)
on 2007-12-12 20:18
(Received via mailing list)
On Dec 12, 2007 9:34 AM, Sven Fuchs <svenfuchs@artweb-design.de> wrote:
> I even linked to that thread. And no, it doesn't explore this issue.

Sorry, should have read closer :/

> following statements will load different files:
>
> require "something" # uses $LOAD_PATH
> Something.called    # uses Dependencies.load_paths

I get it.  If this is the case, it does seem like a bug to me.  As
mentioned in the other thread, I think the official position still
seems to be that you shouldn't have identically-named files, which
would make this a moot point.  However, given that 1) this bug didn't
exist before, 2) there's probably plenty of plugins out there that do
rely on the identically-named-file approach, 3) some people won't want
to buy into the idea that identically named files are bad, then it
seems like this should be fixed.

-- Chad
402602a60e500e85f2f5dc1ff3648ecb?d=identicon&s=25 Sven Fuchs (Guest)
on 2008-01-07 22:01
(Received via mailing list)
Ok, I now created a ticket for this and added a patch accordingly.

See http://dev.rubyonrails.org/ticket/10737

Anybody mind to check this out?

Thanks!


Am 12.12.2007 um 20:17 schrieb Chad Woolley:

>> the issue is present no matter in which order plugins are loaded:
>> Something.called    # uses Dependencies.load_paths
> -- Chad
>
> >

--
sven fuchs      svenfuchs@artweb-design.de
artweb design    http://www.artweb-design.de
gr├╝nberger 65    + 49 (0) 30 - 47 98 69 96 (phone)
d-10245 berlin    + 49 (0) 171 - 35 20 38 4 (mobile)
This topic is locked and can not be replied to.