Upgrade to Pro
— share decks privately, control downloads, hide ads and more …
Speaker Deck
Features
Speaker Deck
PRO
Sign in
Sign up for free
Search
Search
Rails deprecation warning に立ち向かう技術 / v.s. rails...
Search
Sponsored
·
SiteGround - Reliable hosting with speed, security, and support you can count on.
→
megane42
December 20, 2023
Programming
0
700
Rails deprecation warning に立ち向かう技術 / v.s. rails deprecation warnings
megane42
December 20, 2023
Tweet
Share
More Decks by megane42
See All by megane42
Immutable ActiveRecord
megane42
0
300
OSS コミットゴルフのすすめ / Let's play OSS-contribute-golf
megane42
0
110
ゆる計算理論ラジオ / P vs NP for beginner
megane42
1
250
How to Make "DJ giftee"
megane42
1
960
Rails 6 Upgrade "Practical" Guide
megane42
6
1.4k
updated_at に依存したら大変なことになった / Don't depend on updated_at
megane42
0
610
本当は怖い Rails の `build_xxx` / The Hard Facts of `build_xxx` of Rails
megane42
0
270
Other Decks in Programming
See All in Programming
高速開発のためのコード整理術
sutetotanuki
1
430
CSC307 Lecture 07
javiergs
PRO
1
560
あなたはユーザーではない #PdENight
kajitack
4
200
生成AIを使ったコードレビューで定性的に品質カバー
chiilog
1
300
izumin5210のプロポーザルのネタ探し #tskaigi_msup
izumin5210
1
330
カスタマーサクセス業務を変革したヘルススコアの実現と学び
_hummer0724
0
850
今、アーキテクトとして 品質保証にどう関わるか
nealle
0
160
Amazon Bedrockを活用したRAGの品質管理パイプライン構築
tosuri13
5
870
CSC307 Lecture 12
javiergs
PRO
0
440
登壇資料を作る時に意識していること #登壇資料_findy
konifar
4
1.9k
AIプロダクト時代のQAエンジニアに求められること
imtnd
1
430
15年目のiOSアプリを1から作り直す技術
teakun
0
430
Featured
See All Featured
How to Grow Your eCommerce with AI & Automation
katarinadahlin
PRO
1
130
Hiding What from Whom? A Critical Review of the History of Programming languages for Music
tomoyanonymous
2
460
4 Signs Your Business is Dying
shpigford
187
22k
StorybookのUI Testing Handbookを読んだ
zakiyama
31
6.6k
[SF Ruby Conf 2025] Rails X
palkan
2
780
Beyond borders and beyond the search box: How to win the global "messy middle" with AI-driven SEO
davidcarrasco
1
60
Fantastic passwords and where to find them - at NoRuKo
philnash
52
3.6k
A Guide to Academic Writing Using Generative AI - A Workshop
ks91
PRO
0
210
The Impact of AI in SEO - AI Overviews June 2024 Edition
aleyda
5
750
How to Get Subject Matter Experts Bought In and Actively Contributing to SEO & PR Initiatives.
livdayseo
0
72
AI Search: Where Are We & What Can We Do About It?
aleyda
0
7k
Stop Working from a Prison Cell
hatefulcrawdad
274
21k
Transcript
deprecation warning に ⽴ち向かう技術 2023/12/20 gotanda.rb #56 Hikaru Kazama (@megane42)
⾃⼰紹介 • ギフティのバックエンドエンジニア • 最近のコントリビュート:Kaigi on Rails アプリに⽬次を実装 • 実装⽇:最終⽇の翌⽇
課題 • Rails のバージョンアップに伴って、これまで使っていた機能 が deprecation (⾮推奨) になることがある • ぼんやりしているとログに吐かれた
deprecation warning を ⾒逃してしまい、後⽇実際に機能が削除 / 変更されてエラーが 起きてしまう
提案 • 実は deprecation warning が発⽣したときのふるまいを 変更できるので、変えてみましょう
config.active_support.deprecation • ⾮推奨機能を使ってしまったときのふるまいを定義できる • development / test 環境では :raise にしておくと便利
config.active_support.disallowed_deprecation • いきなり全体のふるまいを変えるのはちょっと… という⼈向け • 「この違反は潰した」というものだけを個別に設定すると、 その違反が再発したときだけ raise させたりできる
指定できるアクション • raise (エラーを発⽣) • stderr (標準エラーに出⼒) • log (ログに出⼒)
• notify (ActiveSupport::Notifications で通知) • silence (何もしない) https://api.rubyonrails.org/classes/ActiveSupport/Deprecation/Behavior.html
指定できるアクション • raise (エラーを発⽣) • stderr (標準エラーに出⼒) • log (ログに出⼒)
• notify (ActiveSupport::Notifications で通知) • silence (何もしない) https://api.rubyonrails.org/classes/ActiveSupport/Deprecation/Behavior.html
ActiveSupport::Notifications • 実は Rails の中にはいろんなイベントが⾶び交っている • イベントを subscribe することで、任意の処理を実⾏できる •
initializers などで購読すればよい
Slack 通知してみるなど • 購読するイベントは `deprecation.rails` • `payload[:message]` から警告メッセージが取得可能 • `payload[:callstack]`
からスタックトレースが取得可能
正論 • deprecation warning なんて、テストカバレッジが⼗分⾼けれ ば、1 回テスト流すだけで検知できるんじゃないの?
正論 • deprecation warning なんて、テストカバレッジが⼗分⾼けれ ば、1 回テスト流すだけで検知できるんじゃないの?
まとめ • deprecation warning が発⽣しても、 デフォルトの挙動は単にログに吐くだけ • 設定を変更するとエラーを raise させられる
• 開発環境でおすすめ • 設定を変更するとイベント通知させられる • 本番環境でおすすめ • そもそも Rails にイベント購読という概念があるのがおもしろい