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

[#432][#403][#433][#422] Fix checking for column cache until db connects #438

Merged
merged 1 commit into from
Dec 22, 2013

Conversation

bf4
Copy link
Collaborator

@bf4 bf4 commented Dec 19, 2013

Fix related to #432, #403, #433, #422

Summary: When ActsAsTaggableOn::Taggable::Cache is included, it conditionally adds tag caching methods when the model has any "cached_#{tag_type}_list" column

Details: ActiveRecord::Base.columns makes a database connection and caches the calculated
columns hash for the record as @columns. Since we don't want to add caching
methods until we confirm the presence of a caching column, and we don't
want to force opening a database connection when the class is loaded,
here we intercept and cache the call to :columns as @acts_as_taggable_on_columns
to mimic the underlying behavior. While processing this first call to columns,
we do the caching column check and dynamically add the class and instance methods

Also see
#432 (comment)

Very simplified description of error condition in console

# pre-PR behavior, methods loaded iff db connection exists when model loaded
# User loaded before db connection
ActiveRecord::Base.connected? 
=> false
 User.caching_tag_list_on?
=> NoMethodError: undefined method `caching_tag_list_on?' for User(no database connection):Class
ActiveRecord::Base.connection
=>  ActiveRecord::ConnectionAdapters::SQLite3Adapter 
 User.caching_tag_list_on?
=> NoMethodError: undefined method `caching_tag_list_on?' for User(no database connection):Class

# User loaded after db connection
ActiveRecord::Base.connection
=>  ActiveRecord::ConnectionAdapters::SQLite3Adapter 
 User.caching_tag_list_on?
=> ArgumentError: wrong number of arguments (0 for 1)

# post-PR behavior, methods loaded on db connection
ActiveRecord::Base.connected? 
 => false 
 User.caching_tag_list_on?
NoMethodError: undefined method `caching_tag_list_on?' for User(no database connection):Class
ActiveRecord::Base.connection
=>  ActiveRecord::ConnectionAdapters::SQLite3Adapter 
 User.caching_tag_list_on?
ArgumentError: wrong number of arguments (0 for 1)

@bf4
Copy link
Collaborator Author

bf4 commented Dec 19, 2013

@seuros @aaronchi @shekibobo @joelcogen @dstosik can you confirm this PR fixes the issue for you?

@seuros
Copy link
Collaborator

seuros commented Dec 19, 2013

It seem the the issue is resolved. 👍 Thank you!

end

def acts_as_taggable_on(*args)
super(*args)
initialize_acts_as_taggable_on_cache
Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hmm, looks like we're calling this method twice.. but that's existing behavior

@bf4 bf4 mentioned this pull request Dec 19, 2013
Merged
@bf4
Copy link
Collaborator Author

bf4 commented Dec 19, 2013

@seuros Thanks, since I was only able to duplicate it console, and need to think about how to test.

# we do the caching column check and dynamically add the class and instance methods
def columns
@acts_as_taggable_on_columns ||= begin
db_columns = super
Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The check for table_exists? should not be necessary here

bf4 added a commit that referenced this pull request Dec 22, 2013
[#432][#403][#433][#422] Fix checking for column cache until db connects
@bf4 bf4 merged commit 5f87304 into mbleigh:master Dec 22, 2013
tekniklr pushed a commit to tekniklr/acts-as-taggable-on that referenced this pull request Mar 19, 2021
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

Successfully merging this pull request may close these issues.

2 participants