Tag: ruby

Fighting an “Unknown MySQL error” when connecting to Aurora from Rails

The other day I was struggling with a very weird error when upgrading to Ruby 3. The initial migrations for a Rails app would fail with “Mysql2::Error: Unknown MySQL error (ActiveRecord::StatementInvalid)”, but only in certain environments. The error would occur when Rails tried to check what migrations are already applied by looking at the schema_migrations table.

2022-01-19 09:12:59.205 +0000 [DEBUG]    (1.7ms)  SELECT GET_LOCK('4252831219231700070', 0)
/usr/local/bundle/gems/mysql2-0.5.3/lib/mysql2/client.rb:131: warning: rb_tainted_str_new_cstr is deprecated and will be removed in Ruby 3.2
2022-01-19 09:12:59.222 +0000 [DEBUG]    (2.0ms)  SELECT `schema_migrations`.`version` FROM `schema_migrations` ORDER BY `schema_migrations`.`version` ASC
2022-01-19 09:12:59.224 +0000 [DEBUG]    (1.8ms)  SELECT RELEASE_LOCK('4252831219231700070')
rails aborted!
ActiveRecord::StatementInvalid: Mysql2::Error: Unknown MySQL error
/usr/local/bundle/gems/mysql2-0.5.3/lib/mysql2/client.rb:131:in `_query'

PDF export with the Ruby 3.0.3 docker image

You might happen to use the wicked_pdf gem for PDF output in your Rails app. You might happen to use the wkhtmltopdf-binary gem to provide the required binaries. You might want to get the above to work on the latest (at this point 3.0.3-bullseye) Ruby docker image. Short answer: give up. A bit longer answer: it’s easier than you think.


Patching delayed_job for Ruby 3

Monkey patching is bad. That’s where you should start from. It can cause trouble where you’d least expect it, conflicts with libraries you’d least expect in ways you’d least expect. And yet here I am sharing code for patching the delayed_job gem to (more or less) work with Ruby 3. Doesn’t this violate my own policies? There are a few choices.

  1. give up upgrading to Ruby 3 altogether
  2. monkey patch delayed_job as an emergency fix and make time to figure out what to do
  3. contribute to delayed_job making sure the gem is solid on Ruby 3
  4. get rid of all the .delay calls and switch to another async job library

Stuff that broke in Rails 6.1

Rails uses a “shifted” “semantic” “versioning” which pretty much comes down to the following. Major version: “we’ll most definitely break everything you ever depended on, half of them without warning.” Minor version: “we’ll probably break many stuff you depend on, some of them without warning.” Patch version: “we might accidentally some core APIs, but we promise it’s not intentional (or documented).” Knowing that, I still embarked on the grand endeavor of upgrading from Ruby on Rails 6.0.4.1 to 6.1.4.1. What could possibly go wrong, right?

Railway tracks are suspended above the washed out Tank Hill underpass of the Trans Canada Highway 1 after devastating rain storms caused flooding and landslides, northeast of Lytton, British Columbia, Canada November 17, 2021. B.C. Ministry of Transportation and Infrastructure/Handout via REUTERS
Rails in Canada and on Ruby share (un)surprising similarities (source)

Rails counter_cacheの罠

counter_cacheはいいぞ。 #いいぞ

counter_cacheって?

アプリの大きさや目的に関わらず結構早い段階からいろんなものを数えたくなる。ユーザー何人?記事についてるタグ何個?


ルビーのパパ

昨日またルビーイベント参加してきた。今回はルビーの作者マッツさんの話が聞けるという訳で楽しみだった。実際に気になっていたことや、ここから半年で気になるだろう的なこともいっぱい聞けてよかった。