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

Config not working as expected in development #701

Closed
reefdog opened this issue Jan 8, 2020 · 7 comments
Closed

Config not working as expected in development #701

reefdog opened this issue Jan 8, 2020 · 7 comments

Comments

@reefdog
Copy link

reefdog commented Jan 8, 2020

Hey folks. Unsure what's going awry here, so please let me know what else we can provide.

We're using Chewy 5.1.0 with Rails 5.2 and Ruby 2.5.7. For some reason, neither of the documented approaches for configuration (config/chewy.yml or an initializer with Chewy.settings = {...}) are working.

Specifically, we're trying to set request_strategy to :bypass in development using either of the documented approaches:

# config/chewy.yml
development:
  host: 'localhost'
  request_strategy: :bypass
  request_timeout: 300
# config/initializers/chewy.rb
Chewy.settings = { request_strategy: :bypass }

But neither one works and it remains :atomic:

$ rails c
Chewy console strategy is `urgent`
Loading development environment (Rails 5.2.4.1)
irb(main):001:0> Chewy.request_strategy
=> :atomic

The only way we can get this to stick is with an initializer that assigns Chewy.request_strategy directly:

# config/initializers/chewy.rb
Chewy.request_strategy = :bypass

Which then creates the expected result:

$ rails c
Chewy console strategy is `urgent`
Loading development environment (Rails 5.2.4.1)
irb(main):001:0> Chewy.request_strategy
=> :bypass

(And yes, I confirmed the Rails env is development.)

I'm assuming most people don't have trouble with config, or this would be a bigger deal. So any ideas for how we can figure out what's going on?

🙏

@jonatas
Copy link

jonatas commented Jan 13, 2020

Hello @reefdog , can you please confirm that you're talking about config/chewy.yml and not config/chewy.rb?

@jonatas
Copy link

jonatas commented Jan 13, 2020

I hacked some specs and looks like it's not using the yaml as a proper resource. Check the new specs I added:

        expect(File).to receive(:exist?)
          .with(Pathname.new(__dir__).join('config', 'chewy.yml')).and_return(true)
        expect(File).to receive(:read).and_return(<<~YAML)
        development:
          request_strategy: :bypass
        YAML
        expect(subject.configuration[:request_strategy]).to eq(:bypass)
        expect(subject.request_strategy).to eq(:bypass)

and it fails in the last assertion.

@reefdog
Copy link
Author

reefdog commented Jan 13, 2020

@jonatas Gah, yes config/chewy.yml is my local config file. Apologies for the typo in my issue, I'll edit.

So your test proves that Chewy isn't correctly parsing config out of the YAML file, then?

@jonatas
Copy link

jonatas commented Jan 13, 2020

Please fix it by using the file in the initializers folder as you suggested or submit a PR with the fix.

@reefdog
Copy link
Author

reefdog commented Jan 14, 2020

@jonatas I'm happy to look into contributing a fix, but I'm confused as to why the documentation says to use config/chewy.yml if it doesn't work.

My assumption is that I was doing something wrong, but does configuration via YAML not work at all? If so, any idea why it's documented? Did it work at one point and then stop?

@reefdog
Copy link
Author

reefdog commented Jan 14, 2020

Also, note that we couldn't get either of the two documented solutions to work. The docs say that we should use the initializer like so:

# config/initializers/chewy.rb
Chewy.settings = { request_strategy: :bypass }

But we had to assign it directly, as documented in the original comment:

# config/initializers/chewy.rb
Chewy.request_strategy = :bypass

(I've edited the original comment to explicitly add the failing initializer approach.)

@dalthon
Copy link
Contributor

dalthon commented Feb 19, 2021

This is a duplicate of #495

At rails console strategy :urgent is hardcoded.
https://github.com/toptal/chewy/blob/master/lib/chewy/railtie.rb#L49

We should change it

@dalthon dalthon closed this as completed Feb 19, 2021
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