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

I18n backend fails with whitelisting key functionality. #359

Open
lovenic opened this issue Jun 10, 2021 · 0 comments
Open

I18n backend fails with whitelisting key functionality. #359

lovenic opened this issue Jun 10, 2021 · 0 comments

Comments

@lovenic
Copy link

lovenic commented Jun 10, 2021

Describe the bug

While using i18n backend config.validate_keys = true doesn't work as expected, because we're trying to call

msg = messages.translate("errors.unexpected_key")

        Message.new(
          path: path,
          meta: msg[:meta] || EMPTY_HASH,
          text: msg[:text],
          predicate: nil,
          input: input
        )

but we get TypeError: no implicit conversion of Symbol into Integer from /usr/local/bundle/gems/dry-schema-1.5.6/lib/dry/schema/message_compiler.rb:119:in []'

seems like messages.translate returns array rather than hash with :meta key.

To Reproduce

class BaseContract < Dry::Validation::Contract
  config.messages.backend = :i18n
end
class TestContract < BaseContract
  params do
    config.validate_keys = true

    required(:test).filled(:string)
  end
end
TestContract.new.call({test: 'meow', extra_test: 'bow'})

Expected behavior

It doesn't fails with error and returns failed validation with a correct message.

My environment

  • Ruby version: 2.6.3
  • OS: MacOS Big Sur
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

1 participant