From 5ed4af23727def023b7d073d9302baf8c8d64b1c Mon Sep 17 00:00:00 2001 From: Chandrakant Gopalan Date: Sun, 14 Mar 2021 15:33:15 -0400 Subject: [PATCH 1/6] Raise proper error message if duplicate macros found --- core/dbt/parser/results.py | 16 +++++++++++++++- 1 file changed, 15 insertions(+), 1 deletion(-) diff --git a/core/dbt/parser/results.py b/core/dbt/parser/results.py index f2fc3b9d5f1..d20dbb0d3d6 100644 --- a/core/dbt/parser/results.py +++ b/core/dbt/parser/results.py @@ -125,7 +125,7 @@ def add_macro(self, source_file: SourceFile, macro: ParsedMacro): # subtract 2 for the "Compilation Error" indent # note that the line wrap eats newlines, so if you want newlines, # this is the result :( - msg = line_wrap_message( + dup_macro_msg = line_wrap_message( f'''\ dbt found two macros named "{macro.name}" in the project "{macro.package_name}". @@ -140,6 +140,20 @@ def add_macro(self, source_file: SourceFile, macro: ParsedMacro): ''', subtract=2 ) + dup_path_msg = line_wrap_message( + f"""\ + The file {macro.original_file_path} was parsed multiple times by dbt. + This error happens when a path is duplicated in a dbt_project.yml configuration. + Check your `dbt_project.yml` file path configurations and remove any + duplicated paths to fix this error + """, + subtract=2, + ) + msg = ( + dup_path_msg + if macro.original_file_path == other_path + else dup_macro_msg + ) raise_compiler_error(msg) self.macros[macro.unique_id] = macro From 31989b85d183fa93e4ae5697008c7796cd61ee1a Mon Sep 17 00:00:00 2001 From: Chandrakant Gopalan Date: Sun, 14 Mar 2021 15:46:47 -0400 Subject: [PATCH 2/6] Fix flake8 errors --- core/dbt/parser/results.py | 9 +++++---- 1 file changed, 5 insertions(+), 4 deletions(-) diff --git a/core/dbt/parser/results.py b/core/dbt/parser/results.py index d20dbb0d3d6..5bd75ade29d 100644 --- a/core/dbt/parser/results.py +++ b/core/dbt/parser/results.py @@ -142,10 +142,11 @@ def add_macro(self, source_file: SourceFile, macro: ParsedMacro): ) dup_path_msg = line_wrap_message( f"""\ - The file {macro.original_file_path} was parsed multiple times by dbt. - This error happens when a path is duplicated in a dbt_project.yml configuration. - Check your `dbt_project.yml` file path configurations and remove any - duplicated paths to fix this error + The file {macro.original_file_path} was parsed multiple times + by dbt. This error happens when a path is duplicated in a + dbt_project.yml configuration. + Check your `dbt_project.yml` file path configurations and + remove any duplicated paths to fix this error """, subtract=2, ) From 5c5013191be52146f732e46569e64f4a9d8a853e Mon Sep 17 00:00:00 2001 From: Chandrakant Gopalan Date: Sun, 14 Mar 2021 17:46:53 -0400 Subject: [PATCH 3/6] Fix failing test --- core/dbt/parser/results.py | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/core/dbt/parser/results.py b/core/dbt/parser/results.py index 5bd75ade29d..2bc01cfa50d 100644 --- a/core/dbt/parser/results.py +++ b/core/dbt/parser/results.py @@ -142,9 +142,9 @@ def add_macro(self, source_file: SourceFile, macro: ParsedMacro): ) dup_path_msg = line_wrap_message( f"""\ - The file {macro.original_file_path} was parsed multiple times - by dbt. This error happens when a path is duplicated in a - dbt_project.yml configuration. + The file {macro.original_file_path} for macro {macro.name} + was parsed multiple times by dbt. This error happens when a + path is duplicated in a dbt_project.yml configuration. Check your `dbt_project.yml` file path configurations and remove any duplicated paths to fix this error """, From a8b2942f932d4ae165834f0552e4ae42fc038fb4 Mon Sep 17 00:00:00 2001 From: Chandrakant Gopalan Date: Tue, 16 Mar 2021 13:40:18 -0400 Subject: [PATCH 4/6] Fix duplicate macro path message --- core/dbt/parser/results.py | 10 +++++++--- 1 file changed, 7 insertions(+), 3 deletions(-) diff --git a/core/dbt/parser/results.py b/core/dbt/parser/results.py index 2bc01cfa50d..cfadfe52b34 100644 --- a/core/dbt/parser/results.py +++ b/core/dbt/parser/results.py @@ -142,11 +142,15 @@ def add_macro(self, source_file: SourceFile, macro: ParsedMacro): ) dup_path_msg = line_wrap_message( f"""\ - The file {macro.original_file_path} for macro {macro.name} + The macro {macro.name} in file {macro.original_file_path} was parsed multiple times by dbt. This error happens when a + macro is defined multiple times in the same file, or when a path is duplicated in a dbt_project.yml configuration. - Check your `dbt_project.yml` file path configurations and - remove any duplicated paths to fix this error + To fix this error, check: + + - {macro.original_file_path} + + - The `macro-paths` configurations in dbt_project.yml """, subtract=2, ) From 0e958f3704cb8dfe00052f1e1ae9013e19abed8a Mon Sep 17 00:00:00 2001 From: Chandrakant Gopalan Date: Tue, 16 Mar 2021 13:51:42 -0400 Subject: [PATCH 5/6] Add to changelog --- CHANGELOG.md | 1 + 1 file changed, 1 insertion(+) diff --git a/CHANGELOG.md b/CHANGELOG.md index 9f73c79e77d..141d44fe8e5 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -7,6 +7,7 @@ - Fix variable `_dbt_max_partition` declaration and initialization for BigQuery incremental models ([#2940](https://github.com/fishtown-analytics/dbt/issues/2940), [#2976](https://github.com/fishtown-analytics/dbt/pull/2976)) - Moving from 'master' to 'HEAD' default branch in git ([#3057](https://github.com/fishtown-analytics/dbt/issues/3057), [#3104](https://github.com/fishtown-analytics/dbt/issues/3104), [#3117](https://github.com/fishtown-analytics/dbt/issues/3117))) - Requirement on `dataclasses` is relaxed to be between `>=0.6,<0.9` allowing dbt to cohabit with other libraries which required higher versions. ([#3150](https://github.com/fishtown-analytics/dbt/issues/3150), [#3151](https://github.com/fishtown-analytics/dbt/pull/3151)) +- Raise a proper error message if dbt parses a macro twice due to macro duplication or misconfiguration. ([#2449](https://github.com/fishtown-analytics/dbt/issues/2449)) ### Features - Add optional configs for `require_partition_filter` and `partition_expiration_days` in BigQuery ([#1843](https://github.com/fishtown-analytics/dbt/issues/1843), [#2928](https://github.com/fishtown-analytics/dbt/pull/2928)) From f4c74968bed5982ca0c9422221911bd92e4c9601 Mon Sep 17 00:00:00 2001 From: Chandrakant Gopalan Date: Tue, 16 Mar 2021 13:53:51 -0400 Subject: [PATCH 6/6] Add to contributor list --- CHANGELOG.md | 1 + 1 file changed, 1 insertion(+) diff --git a/CHANGELOG.md b/CHANGELOG.md index 141d44fe8e5..9c066530c11 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -26,6 +26,7 @@ Contributors: - [@pcasteran](https://github.com/pcasteran) ([#2976](https://github.com/fishtown-analytics/dbt/pull/2976)) - [@VasiliiSurov](https://github.com/VasiliiSurov) ([#3104](https://github.com/fishtown-analytics/dbt/pull/3104)) - [@bastienboutonnet](https://github.com/bastienboutonnet) ([#3151](https://github.com/fishtown-analytics/dbt/pull/3151)) +- [@cgopalan](https://github.com/cgopalan) ([#3165](https://github.com/fishtown-analytics/dbt/pull/3165)) ## dbt 0.19.1 (Release TBD)