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
·
Ship Features Fearlessly
Turn features on and off without deploys. Used by thousands of Ruby developers.
→
megane42
December 20, 2023
Programming
0
710
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
310
OSS コミットゴルフのすすめ / Let's play OSS-contribute-golf
megane42
0
110
ゆる計算理論ラジオ / P vs NP for beginner
megane42
1
260
How to Make "DJ giftee"
megane42
1
970
Rails 6 Upgrade "Practical" Guide
megane42
6
1.4k
updated_at に依存したら大変なことになった / Don't depend on updated_at
megane42
0
620
本当は怖い Rails の `build_xxx` / The Hard Facts of `build_xxx` of Rails
megane42
0
270
Other Decks in Programming
See All in Programming
OTP を自動で入力する裏技
megabitsenmzq
0
100
AI駆動開発の本音 〜Claude Code並列開発で見えたエンジニアの新しい役割〜
hisuzuya
4
500
PostgreSQL を使った快適な go test 環境を求めて
otakakot
0
540
Go 1.26でのsliceのメモリアロケーション最適化 / Go 1.26 リリースパーティ #go126party
mazrean
1
390
CSC307 Lecture 13
javiergs
PRO
0
320
New in Go 1.26 Implementing go fix in product development
sunecosuri
0
430
maplibre-gl-layers - 地図に移動体たくさん表示したい
kekyo
PRO
0
260
エラーログのマスキングの仕組みづくりに役立ったASTの話
kumoichi
0
200
Goの型安全性で実現する複数プロダクトの権限管理
ishikawa_pro
2
310
エージェント開発初心者の僕がエージェントを作った話と今後やりたいこと
thasu0123
0
240
Codexに役割を持たせる 他のAIエージェントと組み合わせる実務Tips
o8n
4
1.3k
「やめとこ」がなくなった — 1月にZennを始めて22本書いた AI共創開発のリアル
atani14
0
380
Featured
See All Featured
Navigating Weather and Climate Data
rabernat
0
140
Creating an realtime collaboration tool: Agile Flush - .NET Oxford
marcduiker
35
2.4k
Why Your Marketing Sucks and What You Can Do About It - Sophie Logan
marketingsoph
0
110
SEO in 2025: How to Prepare for the Future of Search
ipullrank
3
3.4k
XXLCSS - How to scale CSS and keep your sanity
sugarenia
249
1.3M
Agile Actions for Facilitating Distributed Teams - ADO2019
mkilby
0
150
職位にかかわらず全員がリーダーシップを発揮するチーム作り / Building a team where everyone can demonstrate leadership regardless of position
madoxten
61
52k
HU Berlin: Industrial-Strength Natural Language Processing with spaCy and Prodigy
inesmontani
PRO
0
260
Kristin Tynski - Automating Marketing Tasks With AI
techseoconnect
PRO
0
190
Designing Powerful Visuals for Engaging Learning
tmiket
0
270
10 Git Anti Patterns You Should be Aware of
lemiorhan
PRO
659
61k
SERP Conf. Vienna - Web Accessibility: Optimizing for Inclusivity and SEO
sarafernandez
1
1.3k
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 にイベント購読という概念があるのがおもしろい