Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[BUG] Uninitialized constant error for IDENTITY/Undefined #73

Closed
bestwebua opened this issue Oct 15, 2022 · 10 comments
Closed

[BUG] Uninitialized constant error for IDENTITY/Undefined #73

bestwebua opened this issue Oct 15, 2022 · 10 comments

Comments

@bestwebua
Copy link

bestwebua commented Oct 15, 2022

Describe the bug

Uninitialized constant error for IDENTITY/Undefined due using short namespaces.

NameError:
  uninitialized constant Dry::Core::ClassAttributes::IDENTITY
        def defines(*args, type: ::Object, coerce: IDENTITY) # rubocop:disable Metrics/PerceivedComplexity

To Reproduce

This issue appear in my project after dry-system version has been bumped from 0.25.0 to 0.26.0 (dry-core has been bumped from 0.8.1 to 0.9.0).

Expected behavior

No errors here :)

My environment

  • Affects my production application: YES
  • Ruby version: ruby 3.1.2p20 (2022-04-12 revision 4491bb740a) [x86_64-darwin20]
  • Bundler version: 2.3.23
  • dry-core version: 0.9.0

PR

PR with fix this issue: #72

@solnic
Copy link
Member

solnic commented Oct 15, 2022

Hey thanks for the report. Could you upgrade to dry-system 0.27.0 and see if this goes away?

@bestwebua
Copy link
Author

bestwebua commented Oct 15, 2022

Hey thanks for the report. Could you upgrade to dry-system 0.27.0 and see if this goes away?

@solnic Yup. After update I see another error:

NameError:
  uninitialized constant Dry::System::Plugins
        extend Dry::System::Plugins

@marian13
Copy link

Describe the bug

Uninitialized constant error for IDENTITY/Undefined due using short namespaces.

NameError:
  uninitialized constant Dry::Core::ClassAttributes::IDENTITY
        def defines(*args, type: ::Object, coerce: IDENTITY) # rubocop:disable Metrics/PerceivedComplexity

To Reproduce

This issue appear in my project after dry-system version has been bumped from 0.25.0 to 0.26.0 (dry-core has been bumped from 0.8.1 to 0.9.0).

Expected behavior

No errors here :)

My environment

  • Affects my production application: YES
  • Ruby version: ruby 3.1.2p20 (2022-04-12 revision 4491bb740a) [x86_64-darwin20]
  • Bundler version: 2.3.23
  • dry-core version: 0.9.0

PR

PR with fix this issue: #72

I am experiencing this error as well, but with dry-validation 😅

Screenshot 2022-10-15 at 19 03 59

@bestwebua
Copy link
Author

@marian13 With full namespaces it works like a charm with next dry stack:

gem 'dry-system', '~> 0.26.0'
gem 'dry-transaction', '0.13.3'
gem 'dry-transformer', '~> 0.1.1'
gem 'dry-validation', '~> 1.9'

@solnic
Copy link
Member

solnic commented Oct 15, 2022

How can I reproduce this? I tried this and it worked:

➜  ~ gem i dry-system
Fetching dry-system-0.27.1.gem
Successfully installed dry-system-0.27.1
1 gem installed

➜  ~ irb
irb(main):001:0> require 'dry-system'
=> true

➜  ~ gem i dry-validation
Successfully installed dry-validation-1.9.0
1 gem installed

➜  ~ irb
irb(main):001:0> require 'dry-validation'
=> true

@solnic
Copy link
Member

solnic commented Oct 15, 2022

@flash-gordon I believe we need to have require "dry/core/constants" in all places that refer to constants, they are not auto-loadable after all. WDYT?

@bestwebua
Copy link
Author

@solnic Here is the place where app crushes:

require 'bundler'
require 'dotenv'
require_relative './environment'

Dotenv.load('.env', ".env.#{System::Environment.current_env}")

require 'dry/system/container' # place where raised an error
require 'zeitwerk'

module System
  class Container < Dry::System::Container
    use :env, inferrer: -> { System::Environment.current_env.to_sym }
    use :zeitwerk

    configure do |config|
      config.component_dirs.add('app') do |dir|
        dir.instance = proc do |component|
          component_type = ->(type) { component.identifier.include?(type) }
          component.loader.constant(component) if %w[jobs mailers serializers].any?(&component_type)
        end
      end

      config.component_dirs.add('lib') do |dir|
        dir.instance = proc do |component|
          component.loader.constant(component) if component.identifier.include?('services')
        end
      end
    end
  end

  Import = System::Container.injector
end

After bumping dry-system to 0.27.0 raised another error:

Failure/Error: require_relative '../system/container'

NameError:
  uninitialized constant Dry::System::Plugins

        extend Dry::System::Plugins
                          ^^^^^^^^^
# ./system/container.rb:9:in `<top (required)>'
# ./spec/spec_helper.rb:7:in `require_relative'
# ./spec/spec_helper.rb:7:in `<top (required)>'
# ------------------
# --- Caused by: ---
# LoadError:
#   cannot load such file -- dry/system/container
#   ./system/container.rb:9:in `<top (required)>'

As I understend my propose with fix is wrong, right?

@solnic
Copy link
Member

solnic commented Oct 15, 2022

You need to do require "dry/system" and it should work. This file sets up zeitwerk and the rest will autoload.

@bestwebua
Copy link
Author

Yup. It's works, thanks:

require 'dry/system/container' -> require 'dry/system'

And sorry for mess.

@solnic
Copy link
Member

solnic commented Oct 16, 2022

@bestwebua I'm glad that it works and no worries. This was a helpful report. I should add more info to the dry-system release notes.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

3 participants