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
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
The Ralph Wiggum Loop: First Principles of Autonomous Development
sembayui
0
3.7k
社内規程RAGの精度を73.3% → 100%に改善した話
oharu121
13
7.6k
ふつうのRubyist、ちいさなデバイス、大きな一年 / Ordinary Rubyists, Tiny Devices, Big Year
chobishiba
1
280
Premier Disciplin for Micro Frontends Multi Version/ Framework Scenarios @OOP 2026, Munic
manfredsteyer
PRO
0
210
The Past, Present, and Future of Enterprise Java
ivargrimstad
0
240
CopilotKit + AG-UIを学ぶ
nearme_tech
PRO
1
130
Fundamentals of Software Engineering In the Age of AI
therealdanvega
1
190
New in Go 1.26 Implementing go fix in product development
sunecosuri
0
340
Go1.26 go fixをプロダクトに適用して困ったこと
kurakura0916
0
330
今更考える「単一責任原則」 / Thinking about the Single Responsibility Principle
tooppoo
3
1.4k
ご飯食べながらエージェントが開発できる。そう、Agentic Engineeringならね。
yokomachi
1
280
AI時代でも変わらない技術コミュニティの力~10年続く“ゆるい”つながりが生み出す価値
n_takehata
2
650
Featured
See All Featured
SEO for Brand Visibility & Recognition
aleyda
0
4.3k
Technical Leadership for Architectural Decision Making
baasie
3
270
Leo the Paperboy
mayatellez
4
1.5k
Build The Right Thing And Hit Your Dates
maggiecrowley
39
3.1k
Agile Actions for Facilitating Distributed Teams - ADO2019
mkilby
0
140
Building Adaptive Systems
keathley
44
2.9k
16th Malabo Montpellier Forum Presentation
akademiya2063
PRO
0
63
Money Talks: Using Revenue to Get Sh*t Done
nikkihalliwell
0
170
[SF Ruby Conf 2025] Rails X
palkan
2
810
Bash Introduction
62gerente
615
210k
What Being in a Rock Band Can Teach Us About Real World SEO
427marketing
0
190
Easily Structure & Communicate Ideas using Wireframe
afnizarnur
194
17k
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 にイベント購読という概念があるのがおもしろい