dbt-labs / dbt-core

dbt enables data analysts and engineers to transform their data using the same practices that software engineers use to build applications.
https://getdbt.com
Apache License 2.0
9.88k stars 1.63k forks source link

[CT-2897] [Feature] Suppress stack trace when a model contract is violated #8266

Open joellabes opened 1 year ago

joellabes commented 1 year ago

Is this your first time submitting a feature request?

Describe the feature

When a model contract fails, there's a lot of guff that gets in the way of seeing the actual issue, and comes dangerously close to spilling out of most consoles (Cloud IDE shown here, but I run my VS Code console smaller than this):

image
Compilation Error in model my_first_dbt_model (models/example/my_first_dbt_model.sql)
  This model has an enforced contract that failed.
  Please ensure the name, data_type, and number of columns in your contract match the columns in your model's definition.

  | column_name                | definition_type | contract_type | mismatch_reason       |
  | -------------------------- | --------------- | ------------- | --------------------- |
  | ID                         | TEXT            | FIXED         | data type mismatch    |
  | THIS_COLUMN_DOESNT_EXIST   |                 | TEXT          | missing in definition |
  | THIS_COLUMN_SHOULDNT_EXIST | TIMESTAMP_LTZ   |               | missing in contract   |

  > in macro assert_columns_equivalent (macros/materializations/models/table/columns_spec_ddl.sql)
  > called by macro default__get_assert_columns_equivalent (macros/materializations/models/table/columns_spec_ddl.sql)
  > called by macro get_assert_columns_equivalent (macros/materializations/models/table/columns_spec_ddl.sql)
  > called by macro snowflake__create_view_as_with_temp_flag (macros/adapters.sql)
  > called by macro snowflake__create_view_as (macros/adapters.sql)
  > called by macro create_view_as (macros/materializations/models/view/create_view_as.sql)
  > called by macro default__get_create_view_as_sql (macros/materializations/models/view/create_view_as.sql)
  > called by macro get_create_view_as_sql (macros/materializations/models/view/create_view_as.sql)
  > called by macro statement (macros/etc/statement.sql)
  > called by macro create_or_replace_view (macros/materializations/models/view/create_or_replace_view.sql)
  > called by macro materialization_view_snowflake (macros/materializations/view.sql)
  > called by model my_first_dbt_model (models/example/my_first_dbt_model.sql)
1 of 2 ERROR creating sql view model dbt_jlabes.my_first_dbt_model ............. [ERROR in 0.88s]
Finished running node model.my_new_project.my_first_dbt_model

It would be better if instead it was like this:

Compilation Error in model my_first_dbt_model (models/example/my_first_dbt_model.sql)
  This model has an enforced contract that failed.
  Please ensure the name, data_type, and number of columns in your contract match the columns in your model's definition.

  | column_name                | definition_type | contract_type | mismatch_reason       |
  | -------------------------- | --------------- | ------------- | --------------------- |
  | ID                         | TEXT            | FIXED         | data type mismatch    |
  | THIS_COLUMN_DOESNT_EXIST   |                 | TEXT          | missing in definition |
  | THIS_COLUMN_SHOULDNT_EXIST | TIMESTAMP_LTZ   |               | missing in contract   |

1 of 2 ERROR creating sql view model dbt_jlabes.my_first_dbt_model ............. [ERROR in 0.88s]
Finished running node model.my_new_project.my_first_dbt_model

Describe alternatives you've considered

No response

Who will this benefit?

People who like concise and usable error messages. I guess this is happening since it's a compiler error, and normally the macros that got us to a compilation error are highly relevant. But in this case they're 100% internal macros so it's not useful.

Are you interested in contributing this feature?

No response

Anything else?

No response

jtcohen6 commented 1 year ago

@joellabes I agree this would be nicer without the full stacktrace!

I also share your instinct that this is because it's a CompilationError, and so we're appending the macro traceback. We should look into seeing if we can have different behavior for ContractError in particular.

graciegoheen commented 1 year ago

Discussed during estimation meeting - May be worth investigating why some compilation errors include a traceback, where others don't.

github-actions[bot] commented 9 months ago

This issue has been marked as Stale because it has been open for 180 days with no activity. If you would like the issue to remain open, please comment on the issue or else it will be closed in 7 days.

joellabes commented 9 months ago

Don't leave me