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

Issues with custom versions table names in 4.0.0.beta.2 #488

Closed
bramswenson opened this issue Feb 24, 2015 · 7 comments
Closed

Issues with custom versions table names in 4.0.0.beta.2 #488

bramswenson opened this issue Feb 24, 2015 · 7 comments
Milestone

Comments

@bramswenson
Copy link

Occasionally In normal development environment, and regularly using spring it seems that PaperTrail 4.0.0.beta.2 looses track of the proper table name for version models. I have many version models in my rather large application. Each with its own table and custom class. PaperTraill::Version has been modified with self.abstract_class = true and is only used as such. Since upgrading to 4.0.0.beta.2 if I reload the application from the console with reload! things go haywire. The fact that reload! can consistently reproduce the issue points some to why spring just wont work at all. This seems to be some type of preload/autoload issue. I'm pretty sure this would not manifest in production environments where code is not reloaded, but I could be wrong. Here is an example of the problem in action:

$ be rails console                                                                  ✹
Loading development environment (Rails 3.2.21)
[1] pry(main)> StoryTagVersion.count
   (0.3ms)  SELECT COUNT(*) FROM `dk4_dev_versions`.`story_tag_versions` 
=> 1
[2] pry(main)> reload!
Reloading...
   (0.5ms)  SELECT DATABASE() as db
   (0.4ms)  SELECT DATABASE() as db
   (0.5ms)  SELECT DATABASE() as db
   (0.4ms)  SELECT DATABASE() as db
   (0.4ms)  SELECT DATABASE() as db
   (0.3ms)  SELECT DATABASE() as db
=> true
[3] pry(main)> StoryTagVersion.count
ActiveRecord::StatementInvalid: Mysql2::Error: Table 'dk4_dev_versions.versions' doesn't exist: SHOW FULL FIELDS FROM `versions`
from .bundle/bundle/ruby/1.9.1/gems/activerecord-3.2.21/lib/active_record/connection_adapters/abstract_mysql_adapter.rb:245:in `query
@bramswenson
Copy link
Author

This issue pretty much breaks my test suite since it reloads code (like pretty much all rails test suites). It runs fine for a while then everything starts failing due to the same type of exception as above.

@batter
Copy link
Collaborator

batter commented Feb 24, 2015

See #483, I think that person may have more insight

@bramswenson
Copy link
Author

Interesting. I'm not using the PaperTrail::Rails::Engine.eager_load! statement as I am in rails 3.2 and the docs claim that it is not needed unless rails >= 4.0. I'm going to try a few more things and report back. Thanks for the info.

@bramswenson
Copy link
Author

Using 3.0.6 we did not explicitly use self.table_name in the version model definitions. Setting the table name explicitly made all my tests work again, but does not fix issues with reload! or spring.

@batter
Copy link
Collaborator

batter commented Feb 27, 2015

Actually, what the docs are trying to say is that the PaperTrail::Rails::Engine.eager_load! statement is needed for PaperTrail version 4.x, but not for version 3.x. The version of ActiveRecord / Rails being used is not relevant with regards to that. So have you tried putting that statement at the top of your custom initializer?

@TobiasBales
Copy link

I have the same issue.
beta2 with rails 4.2.0 but for me having self.table_name in my version models does not fix the issue.
The issue persists itself when modifying some code that force a reload in the dev environment.
So start server -> works -> save app/controllers/application_controller.rb -> reload -> does not work anymore

@jaredbeck
Copy link
Member

I think this is a duplicate of #492 and others like it. We have addressed this issue by asking people to stop using an initializer. We've found that initializers aren't compatible with reload!. The new recommendation is given in the readme, and was added to the readme by #557.

@jaredbeck jaredbeck added this to the 4.0.0 milestone Aug 1, 2015
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

4 participants