Skip to content

Commit

Permalink
Fix lookup_tables if a table doesn't exist (#30)
Browse files Browse the repository at this point in the history
  • Loading branch information
kokorin authored Jul 7, 2024
1 parent b7b7f9f commit 23c193a
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 7 deletions.
25 changes: 18 additions & 7 deletions dbt_pumpkin/loader.py
Original file line number Diff line number Diff line change
Expand Up @@ -243,8 +243,8 @@ def event_callback(event: EventMsg):
result_callback(potential_result[operation_name])
else:
logger.debug("Ignoring potential result: no '%s' key: %s", operation_name, potential_result)
except ValueError:
logger.exception("Failed to parse potential result %s", event.info.msg)
except Exception:
logger.exception("Failed to parse potential result %s", event.info)

res: dbtRunnerResult = dbtRunner(callbacks=[event_callback]).invoke(args)

Expand All @@ -264,14 +264,25 @@ def _do_lookup_tables(self) -> list[Table]:
}

tables: list[Table] = []
processed: list[str] = []

def on_result(result: dict):
table = Table(
resource_id=ResourceID(result["resource_id"]),
columns=[TableColumn(**c) for c in result["columns"]],
resource_id: str = result["resource_id"]
processed.append(resource_id)
logger.info("Processing %s / %s: %s", len(processed), len(raw_resources), resource_id)

columns: list[dict] = result["columns"]
# If tables doesn't exist columns is None
if not columns:
logger.warning("Relation doesn't exist: %s", resource_id)
return

tables.append(
Table(
resource_id=ResourceID(resource_id),
columns=[TableColumn(**c) for c in columns],
)
)
tables.append(table)
logger.info("Looked up %s / %s: %s", len(tables), len(raw_resources), table.resource_id)

self._run_operation("lookup_tables", project_vars, on_result)

Expand Down
4 changes: 4 additions & 0 deletions tests/test_loader.py
Original file line number Diff line number Diff line change
Expand Up @@ -431,3 +431,7 @@ def test_selected_resource_tables(loader_all):
],
),
}


def test_selected_resource_tables_no_actual_tables(loader_configured_paths):
assert [] == loader_configured_paths.lookup_tables()

0 comments on commit 23c193a

Please sign in to comment.