Coder Social home page Coder Social logo

Comments (8)

 avatar commented on May 23, 2024

Fixed in 9c80976

from acts-as-taggable-on.

dsmalko avatar dsmalko commented on May 23, 2024

Problem is not solved.

Code:

Post.create! :tag_list = "one, two"

post = Post.first
post.save!

post = Post.first
post.tag_list # => []
post.cached_tag_list # => "
post.tags # => [#<Tag id: 5, name: "one">, #<Tag id: 6, name: "thow">]

from acts-as-taggable-on.

ironoxid avatar ironoxid commented on May 23, 2024

I confirm. Problem is not solved. Critical.

from acts-as-taggable-on.

ironoxid avatar ironoxid commented on May 23, 2024

Hi! I confirm. Problem isn't solved and remains critical.
About what dsmalko said:

  1. post.tag_list is empty after save! because it (just) load tags from cached_tag_list if caching is enabled
  2. cached_tag_list is empty because save_cached_tag_list sets it to an empty string on save! because tag_list_cache_on returns nothing (@my_custom_tag_list is not initialized - look at tag_list_cache_on)

This bug is critical. Not only cache is not reliable but also we loose taggings if fields about our tags are filled with my_custom_tag_list method (it's empty due to cached and so... bye bye baby on form submit - argh!).

Today i spend one hour to figure out what was happening.
This is my patch. It seems to work well

/lib/acts_as_taggable_on/acts_as_taggable_on.rb @387
remove:
send(:"cached_#{tag_type.singularize}list=", tag_list_cache_on(tag_type.singularize).to_a.flatten.compact.join(', '))
use:
list = tag_list_cache_on(tag_type.singularize)
send(:"cached
#{tag_type.singularize}_list=", list.to_a.flatten.compact.join(', ')) if list.any?

My patch takes hash from tag_list_cache_on and check if it's empty. Only if it's not empty I update cache column. If tag_list_cache_on returns {} I assume that @my_custom_tag_list is not initialized, so there is no change about tags and no need to update cache column (this avoid to save empty cache columns when @my_custom_tag_list is not initialized).
Anyway I can't be completely sure about what I assume at the moment, but I think that hash cannot be empty, just because it's a pair of owner => tags and if there is no owner for a tag (or not tags at all) we always have at least a nil key, for example {nil => []}. Isn't it?

I'm testing. For the moment my patch works well.
I'm sorry for my bad english! :)

from acts-as-taggable-on.

ironoxid avatar ironoxid commented on May 23, 2024

Also If you don't want to patch your plugin or wait a fix, just call your_custom_tag_list method before save so instance variable will be initialized

from acts-as-taggable-on.

ironoxid avatar ironoxid commented on May 23, 2024

Testing and one week on production. Patch is ok.

from acts-as-taggable-on.

 avatar commented on May 23, 2024

I've fixed this problem in version 2.0.0 which was just released

from acts-as-taggable-on.

ironoxid avatar ironoxid commented on May 23, 2024

ty!

from acts-as-taggable-on.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.