Tag permalink bug and bad Content state values in Typo Rev 1528 1

Posted by Ryan Kinderman Sat, 22 Sep 2007 18:13:27 GMT

For those Typo users out there, this might be helpful.

As usually happens once every 3 or 4 blog posts, a few days ago I discovered a bug in Typo that cripples my blog and causes me to have to bring it down for a while. I'm not sure exactly which revision it was; one from version 4.0.2 I believe. Finding bugs so frequently probably has something to do with the fact that my idea of "upgrading" is doing an svn up from trunk and running db:migrate RAILS_ENV=production. Anyways, each time this happens, I end up spending at least 2 hours getting into "Typo debug mode", once getting passed "oh crap my blog is screwed mode", and fixing the problem. I don't mind debugging Typo. Having to do it now and then wouldn't be a problem if the types of problems I found were edge cases; unfortunately, they're usually not. These are things that, most definitely, should be covered by unit tests somewhere and caught when they get broken. This time around, I found three issues of this type.

The first issue was as simple as forgetting to update the values in the state column of the contents table in or before database migration 058. These values apparently were valid at some point with values such as ContentState::Ham, ContentState::Spam, ContentState::Published, and so on. However, they are now supposed to be simply ham, spam, and published, respectively. Not updating this data causes migration 058 to fail with Content complaining about an invalid state value. I had to go into mysql and update the values manually.

The second problem is also a simple oversight. After running migration 058, all comments are now stored in a table called feedback. Fine. However, whereas before the comments were displayed in the blog, after running the migration, you'll notice that they're not. This is because there is a published field in the feedback table that indicates whether a comment should be shown or not. After running migration 058, the value of this field for all comments on the blog is 0 (zero), which causes a comment to not be shown. Simply set this value to 1, and the comments are back again.

The third issue, which I discovered by accident from having a tail -f log/production.log running whilst fixing the first bug. I noticed that, every once in a while, a request would come in for Parameters: {"action"=>"show", "id"=>"some_category", "controller"=>"categories"}, which would result in an ActiveRecord::RecordNotFound error to be raised from Category.find_by_permalink. I noticed that the value of params[:id] was actually the name of a tag, not a category. So, I traced the error to Tag.permalink_url, which looked like this:

File: typo/app/models/tag.rb

def permalink_url(anchor=nil, only_path=true)
  blog = Blog.find(1) # remove me...

  blog.url_for(
    :controller => 'categories',
    :action => 'show',
    :id => permalink
  )
end

Woops! I guess we don't want to construct a URL for CategoriesController as the permalink for a Tag. I just changed :controller => 'categories' to :controller => 'tags' and the problem was fixed.

Addendum: Updated this entry to include a description of and resolution to the issue with the feedback.published database field.

Comments

Leave a comment

  1. Piers Cawley 2 days later:

    Oh damn. Those would be my fault.

    And yes, typo needs a better test suite. Oh by ghod does it need a better test suite.

Comments