dbt Cloud環境で『非推奨の警告』が出てきた時の対処法(dbt Core v1.10.8 汎用テストにおけるTOPレベル引数設定)
小ネタです。
dbtで非推奨(Deprecated)の警告が出てきた時の対処方法について、手順をまとめておこうと思います。
遭遇した警告内容
先日までに行っていた各種チュートリアルを実践していたdbt Cloudの環境にて改めて本番環境へのデプロイを実施したところ、処理自体は正常に終了していたのですが以下のような『非推奨の警告(Deprecated detected)』が併せて表示されていました。
実践内容:
遭遇した内容はこちら:
対処方法(#11847: Deprecate top-level argument properties in generic tests)
状況や内容を調べてみると、どうやら直近のdbt Coreバージョン(#11847)で『テストの記載方法』に変更が入ったようです。直近のリリースとなるdbt Core v1.10.8で初めて表示されるようになった警告となっている模様。
具体的には汎用テストで呼び出されるカスタムトップレベルプロパティを指定する機能が非推奨となったことにより、arguments
というプロパティを追加指定する必要が出てきたという内容です。dbt v1.10以降は、すべてのテスト引数をarguments
プロパティ配下で記述することが求められるようになりました。
詳細は以下ドキュメントに記載がありますのでご参照ください。
実際に対象箇所を修正していきます。dbtではこういった非推奨の警告の詳細を確認する際、dbt parse --no-partial-parse --show-all-deprecations
というコマンドでその情報を確認することが出来ます。あら便利。
-
--show-all-deprecations
:すべての非推奨インスタンスを詳細に表示 -
--no-partial-parse
:パース時にも検出される警告を含める
コマンドを実行してみます。都合3つの警告が表示されました。
(dbt parseコマンド実行結果)
警告内容の詳細は以下の通り。models/marts/core/core.yml
に2箇所、models/staging/tpch/tpch_sources.yml
に1箇所、それぞれどの項目におけるテストの記載かまで詳細に言及されています。
XX:XX:XX Cloud CLI invocation created: XxxxxXx-XXxX-xxxx-xxxx-xxxxxxxxx
XX:XX:XX Running dbt...
XX:XX:XX [[33mWARNING[0m][MissingArgumentsPropertyInGenericTestDeprecation]: Deprecated functionality
Found top-level arguments to test `relationships` defined on 'fct_orders' in
package 'shinyaa31_dbt_snowflake_sandbox' (models/marts/core/core.yml).
Arguments to generic tests should be nested under the `arguments` property.
XX:XX:XX [[33mWARNING[0m][MissingArgumentsPropertyInGenericTestDeprecation]: Deprecated functionality
Found top-level arguments to test `accepted_values` defined on 'fct_orders' in
package 'shinyaa31_dbt_snowflake_sandbox' (models/marts/core/core.yml).
Arguments to generic tests should be nested under the `arguments` property.
XX:XX:XX [[33mWARNING[0m][MissingArgumentsPropertyInGenericTestDeprecation]: Deprecated functionality
Found top-level arguments to test `relationships` defined on 'tpch_lineitem' in
package 'shinyaa31_dbt_snowflake_sandbox'
(models/staging/tpch/tpch_sources.yml). Arguments to generic tests should be
nested under the `arguments` property.
XX:XX:XX Performance info: /app/dbt_project/XxxxxXx-XXxX-xxxx-xxxx-xxxxxxxxx/target/perf_info.json
XX:XX:XX [[33mWARNING[0m][DeprecationsSummary]: Deprecated functionality
Summary of encountered deprecations:
- MissingArgumentsPropertyInGenericTestDeprecation: 3 occurrences
記載内容に従って内容を修正します。これは修正前(Before)。
(修正前の設定ファイル内容)
そしてこちらが修正後(After)。インデントも併せて整備する形で追記しました。こんな感じで指摘箇所を全て修正し、
(修正後の設定ファイル内容)
開発環境でテストを実行(dbt test
)。問題無くテストが通ることを確認後、変更をリポジトリに反映させます。
(dbt test実行結果)
そして本番環境へのデプロイを実行。今度は非推奨の警告無しでジョブが正常終了していることが確認出来ました!
まとめ
という訳で、dbt(dbt Cloud)における非推奨の警告が出てきた時の対処方法について、実行記録を交えてまとめてみました。dbtはこういった『バージョンアップにおける非推奨の警告』を出す仕組み、出てきた時の対処方法を共有する仕組みが整っており、対処もとてもスムーズにできることが分かりました。(対処件数が少ないこともあり、ものの30分も経たずに完了出来ました)
この内容がどなたかの参考になりましたら幸いです。
参考: