Skip to content

Edge case not properly handled in get_columns_and_types macro #769

@dlahyani

Description

@dlahyani

This is the problematic excerpt from the macro:

   {%- set relation = adapter.get_relation(
          database=database_name,
          schema=schema_name,
          identifier=table_name) -%}

    {%- set columns_from_relation = adapter.get_columns_in_relation(relation) -%}

This code is problematic in case the requested relation does not exist. In that case adapter.get_relation returns None, so we end up passing None to adapter.get_columns_in_relation which does not expects None.

When using dbt-bigquery adapter it fails with an exception and a cryptic message:

Flow run encountered an exception. 
RuntimeError: Runtime Error
  'NoneType' object has no attribute 'database'

It would be better if before calling to adapter.get_columns_in_relation the macro would check if relation is None and raise an explicit compilation error in that case with a proper error message.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions