Skip to content

Namespace conflict issue after 2.2.0 #98

Description

@shrkw

This is not global issue, maybe a kind of case report.

2.2.0 contains big refactoring (#65) and it makes sense. However compatibility code made an issue on my code.

I have Parts module,

module Parts
  class Foo; end
end

And with 2.1.1, it works fine.

$ bundle exec irb
2.7.2 :001 > require_relative 'parts/foo'
 => true 
2.7.2 :002 > require 'net/http/post/multipart'
 => true 
2.7.2 :003 > Parts::Foo.class
 => Class 
2.7.2 :004 > Parts.constants
 => [:Foo, :Part, :EpiloguePart, :FilePart, :ParamPart] 

However, with 2.2.0, it have loading order issue.

When load modules on following order, it works.

  1. Multipart gem
  2. my Parts module
2.7.2 :001 > require 'net/http/post/multipart'
 => true 
2.7.2 :003 > Multipart::Post::Parts.class
 => Module 
2.7.2 :006 > require_relative 'parts/foo'
 => true 
2.7.2 :007 > Parts.class
 => Module 
2.7.2 :011 >  Parts.constants
 => [:Foo] 

But when following order, it does not work.

  1. my Parts module
  2. Multipart gem
2.7.2 :001 > require_relative 'parts/foo'
 => true 
2.7.2 :002 > require 'net/http/post/multipart'
/usr/local/rvm/gems/ruby-2.7.2/gems/multipart-post-2.2.3/lib/multipart/post/parts.rb:151: warning: already initialized constant Parts
/workspaces/sandbox-ruby/simple/parts/foo.rb:3: warning: previous definition of Parts was here
 => true                                                            
2.7.2 :003 > Parts::Foo
Traceback (most recent call last):
        21: from /usr/local/rvm/gems/ruby-2.7.2/bin/ruby_executable_hooks:22:in `<main>'
        20: from /usr/local/rvm/gems/ruby-2.7.2/bin/ruby_executable_hooks:22:in `eval'
        19: from /usr/local/rvm/gems/ruby-2.7.2/bin/irb:23:in `<main>'
        18: from /usr/local/rvm/gems/ruby-2.7.2/bin/irb:23:in `load'
        17: from /usr/local/rvm/gems/ruby-2.7.2/gems/irb-1.4.1/exe/irb:11:in `<top (required)>'
(irb):3:in `<main>': uninitialized constant Multipart::Post::Parts::Foo (NameError)

I guess it led by here

Parts = Multipart::Post::Parts
, and it is for compatibility.

If that part of code change, it would be breaking change. so, I'm not sure how it should be fixed.

Do you have any ideas? Like applying a monkey patch?

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions