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

Rails 6.1.4 throws NameError: uninitialized constant ThinkingSphinx::ActiveRecord when running tasks #1199

Closed
jasongorst opened this issue Aug 6, 2021 · 5 comments

Comments

@jasongorst
Copy link

Rails 6.1.4 with thinking-sphinx 5.2.0 throws a NameError when running tasks.

I created a bare application having just a single model having 2 attributes and an index file, and got the same error on ts:rebuild (or ts:clear or whatever).

pat added a commit that referenced this issue Aug 8, 2021
This isn't quite as neat as ea8bc34
(as I like the idea of waiting until ActiveRecord is loaded by Rails
itself), but it seems Rake tasks don't always load ActiveRecord, and so
we end up in a situation where indices are being loaded without TS's
ActiveRecord components being available (see
#1199).

But: the main issue was that prior to @jdelStrother's good work, AR
configuration in initialisers was being ignored. This new approach
waits until after initialisers have been run, so it should be fine.
@pat
Copy link
Owner

pat commented Aug 8, 2021

Thanks @jasongorst for reporting this - I've put together a fix that works in my test app, but perhaps you want to bundle from the develop branch to confirm it's fine by you? @jdelStrother would appreciate your eyes over this too if you have a chance, given it's an evolution of your improvements :) (See ea35340)

@jasongorst
Copy link
Author

jasongorst commented Aug 8, 2021 via email

@pat
Copy link
Owner

pat commented Aug 9, 2021

Thanks for that confirmation Jason - I've just published v5.2.1 with the fix :)

@jdelStrother
Copy link
Contributor

Thanks @jasongorst for reporting this - I've put together a fix that works in my test app, but perhaps you want to bundle from the develop branch to confirm it's fine by you? @jdelStrother would appreciate your eyes over this too if you have a chance, given it's an evolution of your improvements :) (See ea35340)

Yeah, think this is OK. It's a shame that it forces ActiveRecord to load for unrelated things like assets:precompile, but in practice it probably doesn't have much noticeable impact, and I don't see a clean alternative. 😕

@pat
Copy link
Owner

pat commented Aug 13, 2021

Yeah, it's not as neat as your solution, but I guess this is what we're stuck with. Thanks for the confirmation Jonathan :)

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

No branches or pull requests

3 participants