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

Custom primary key lost on reload #1125

Closed
atomical opened this issue Feb 28, 2019 · 3 comments
Closed

Custom primary key lost on reload #1125

atomical opened this issue Feb 28, 2019 · 3 comments

Comments

@atomical
Copy link

atomical commented Feb 28, 2019

I'm not sure if this is a Rails (4.2.8) issue or a Thinking Sphinx (4.0.0) issue. In the development environment after a reload the the primary_key on the model doesn't appear to be set and calling count on an instance of ThinkingSphinx::Search tries to do the query with id instead of the primary key.

Edit: After doing some digging this appears to be happening with all models, but the default is :id so it doesn't error out for those models.

ThinkingSphinx::Middlewares::ActiveRecordTranslator
(byebug) index_for(model)
#<struct primary_key=:id>
pat added a commit that referenced this issue Mar 2, 2019
I feel like I've hit this problem before, and I thought I'd restructured things in v3 onwards to avoid it, but I guess not. It's reared its head again in #1125 - the cached configuration's indices kept onto their old references to models, whereas models returned from ActiveRecord search calls were using the new references, and thus not quite matching. It wasn't a problem if all models were using the default primary key of 'id', but otherwise with alternative primary keys things would break.
@pat
Copy link
Owner

pat commented Mar 2, 2019

I'm surprised this issue hasn't cropped up before, but thanks for logging it! I've pushed a fix to the develop branch, and will be a part of the next release (hopefully within the coming week). If you want something in your app now, you can put the following in your config/environment.rb file:

config.to_prepare do
  ThinkingSphinx::Configuration.reset
end

@atomical
Copy link
Author

atomical commented Mar 2, 2019

Thanks, we appreciate it!

@atomical atomical closed this as completed Mar 2, 2019
@pat
Copy link
Owner

pat commented Mar 9, 2019

Just published v4.2.0 which includes this fix :)

h3nnn4n pushed a commit to jobscore/thinking-sphinx that referenced this issue May 14, 2019
I feel like I've hit this problem before, and I thought I'd restructured things in v3 onwards to avoid it, but I guess not. It's reared its head again in pat#1125 - the cached configuration's indices kept onto their old references to models, whereas models returned from ActiveRecord search calls were using the new references, and thus not quite matching. It wasn't a problem if all models were using the default primary key of 'id', but otherwise with alternative primary keys things would break.
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

2 participants