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

Can't boot rails or run specs when this gem is loaded as a dependency of another. Works if it's in the Gemfile. #451

Closed mattgibson closed 1 year ago

mattgibson commented 1 year ago

Describe the bug

With a Gemfile like this:

gem 'dry-matcher',               '~> 0.8.3'
gem 'dry-monads',                '~> 1.4.0'
gem 'dry-struct',                '~> 1.1.1'
gem 'dry-validation',            '~> 1.7.0'

I get this error when I start up the app:

NameError:
  uninitialized constant Dry::Schema::PredicateRegistry
# /Users/matthewgibson/.asdf/installs/ruby/3.1.2/lib/ruby/gems/3.1.0/gems/dry-schema-1.11.3/lib/dry/schema/config.rb:25:in `<class:Config>'
# /Users/matthewgibson/.asdf/installs/ruby/3.1.2/lib/ruby/gems/3.1.0/gems/dry-schema-1.11.3/lib/dry/schema/config.rb:14:in `<module:Schema>'
# /Users/matthewgibson/.asdf/installs/ruby/3.1.2/lib/ruby/gems/3.1.0/gems/dry-schema-1.11.3/lib/dry/schema/config.rb:8:in `<module:Dry>'
# /Users/matthewgibson/.asdf/installs/ruby/3.1.2/lib/ruby/gems/3.1.0/gems/dry-schema-1.11.3/lib/dry/schema/config.rb:7:in `<main>'
# /Users/matthewgibson/.asdf/installs/ruby/3.1.2/lib/ruby/gems/3.1.0/gems/bootsnap-1.9.4/lib/bootsnap/load_path_cache/core_ext/kernel_require.rb:23:in `require'

With a Gemfile like this

gem 'dry-matcher',               '~> 0.8.3'
gem 'dry-monads',                '~> 1.4.0'
# Seems to a be a bug with 1.11.3 uninitialized constant Dry::Schema::PredicateRegistry
# https://stackoverflow.com/questions/74894483/dry-validation-dry-schema-uninitialized-constant-dryschemapredicateregistry
# The bug only shows up if this explicit gem is not in the Gemfile. If it's here, then
# it somehow doesn't have a problem, despite it being the same version. Assuming it's load order.
gem 'dry-schema',                '~> 1.11.3'
gem 'dry-struct',                '~> 1.1.1'
gem 'dry-validation',            '~> 1.7.0'

The error is not there.

I assume there is some issue with load order/zeitwerk.

To Reproduce

Make a Rails app with the above Gemfile and try to start it up, or run some specs.

Expected behavior

No error shows up.

My environment

flash-gordon commented 1 year ago

Try updating gems to later versions, it's not possible to express all compatibility requirements across all versions and gems using rubygems specifications. Or maybe it could be done but will create more problems than it solves.

P.S. dry-matcher 1.0 was released on the 1st of Jan P.P.S. I would drop it in favor of pattern matching tbh.