dry-rb / dry-schema

Coercion and validation for data structures
https://dry-rb.org/gems/dry-schema
MIT License
415 stars 108 forks source link

Dry::Schema::Messages::Abstract undefined #459

Closed krainboltgreene closed 10 months ago

krainboltgreene commented 1 year ago

Describe the bug

Dry::Schema::Messages::Abstract in my application doesn't exist and I don't see anywhere in the gem where it's required?

From: /Users/krainboltgreene/.asdf/installs/ruby/3.1.2/lib/ruby/gems/3.1.0/gems/dry-schema-1.13.0/lib/dry/schema/messages.rb:23 Dry::Schema::Messages.setup:

    16: public def setup(config)
    17:   backend_class = BACKENDS.fetch(config.backend) do
    18:     raise "+#{config.backend}+ is not a valid messages identifier"
    19:   end
    20: 
    21:   namespace = config.namespace
    22:   binding.pry
 => 23:   options = config.to_h.select { |k, _| Abstract.setting_names.include?(k) }

My environment

flash-gordon commented 1 year ago

It is autoloaded by zeitwerk. The constant is defined here https://github.com/dry-rb/dry-schema/blob/8de4754d2506dbbca54dcff197e48976d7564420/lib/dry/schema/messages/abstract.rb

contentfree commented 10 months ago

Zeitwerk doesn't autoload it for me. I'm getting this error too:

/usr/local/bundle/gems/dry-schema-1.13.3/lib/dry/schema/messages.rb:22:in `block in setup': uninitialized constant Dry::Schema::Messages::Abstract (NameError)

        options = config.to_h.select { |k, _| Abstract.setting_names.include?(k) }
                                              ^^^^^^^^
        from /usr/local/bundle/gems/dry-schema-1.13.3/lib/dry/schema/messages.rb:22:in `select'
        from /usr/local/bundle/gems/dry-schema-1.13.3/lib/dry/schema/messages.rb:22:in `setup'
        from /usr/local/bundle/gems/dry-schema-1.13.3/lib/dry/schema/rule_applier.rb:21:in `block in <class:RuleApplier>'
flash-gordon commented 10 months ago

@contentfree do you have require 'dry/schema' anywhere that runs before?

contentfree commented 10 months ago

I do not.

On Thu, Nov 9, 2023 at 6:14 AM Nikita Shilnikov @.***> wrote:

@contentfree https://github.com/contentfree do you have require 'dry/schema' anywhere that runs before?

— Reply to this email directly, view it on GitHub https://github.com/dry-rb/dry-schema/issues/459#issuecomment-1803635226, or unsubscribe https://github.com/notifications/unsubscribe-auth/AAACVTTBAETZRMTKPEINGKTYDS3JPAVCNFSM6AAAAAAXKFXWP2VHI2DSMVQWIX3LMV43OSLTON2WKQ3PNVWWK3TUHMYTQMBTGYZTKMRSGY . You are receiving this because you were mentioned.Message ID: @.***>

flash-gordon commented 10 months ago

Then you'll need to add it somewhere and it should work.

contentfree commented 10 months ago

I still get this after adding require 'dry/schema'. To fix, I have to require 'dry/schema/messages/abstract' explicitly.

flash-gordon commented 10 months ago

That's odd. I suggest you update other dry-* dependencies as well, it may be the cause. If this doesn't help, check if your code doesn't contain specific require's like require 'dry/schema/messages/abstract' and has require 'dry/schema' instead.