Skip to content

Commit 501fc1f

Browse files
committed
lint fixes
1 parent b666dbe commit 501fc1f

1 file changed

Lines changed: 49 additions & 39 deletions

File tree

elementary/clients/dbt/command_line_dbt_runner.py

Lines changed: 49 additions & 39 deletions
Original file line numberDiff line numberDiff line change
@@ -51,10 +51,10 @@ def __init__(
5151
)
5252
self.raise_on_failure = raise_on_failure
5353
self.env_vars = env_vars
54-
54+
5555
# Apply databricks compatibility patch for version 1.10.2
5656
self._apply_databricks_compatibility_patch()
57-
57+
5858
if force_dbt_deps:
5959
self.deps()
6060
elif run_deps_if_needed:
@@ -322,83 +322,93 @@ def _run_deps_if_needed(self):
322322

323323
if should_run_deps:
324324
self.deps()
325-
325+
326326
def _apply_databricks_compatibility_patch(self):
327327
"""Apply monkey patch to fix dbt-databricks 1.10.2 compatibility issues"""
328328
try:
329-
from dbt.adapters.databricks import parse_model
330-
import logging
331-
332-
# Define safe wrapper functions
333-
def is_unsupported_object(model):
329+
from typing import Any, Optional
330+
331+
from dbt.adapters.databricks import parse_model # type: ignore
332+
333+
def is_unsupported_object(model: Any) -> bool:
334334
"""Check if the object is a Macro or other unsupported type"""
335-
return hasattr(model, '__class__') and 'Macro' in str(model.__class__)
336-
337-
def safe_catalog_name(model):
335+
return hasattr(model, "__class__") and "Macro" in str(model.__class__)
336+
337+
def safe_catalog_name(model: Any) -> str:
338338
try:
339339
if is_unsupported_object(model):
340-
logger.debug(f"Received unsupported object type for catalog_name, using unity as default")
341-
return 'unity'
340+
logger.debug(
341+
"Received unsupported object type for catalog_name, using unity as default"
342+
)
343+
return "unity"
342344
# Handle RelationConfig objects
343-
if hasattr(model, 'config') and model.config and hasattr(model.config, 'get'):
344-
catalog = model.config.get('catalog')
345+
if (
346+
hasattr(model, "config")
347+
and model.config
348+
and hasattr(model.config, "get")
349+
):
350+
catalog = model.config.get("catalog")
345351
if catalog:
346352
return catalog
347353
# Fallback to unity catalog
348-
return 'unity'
354+
return "unity"
349355
except Exception as e:
350-
logger.debug(f"Failed to parse catalog name from model: {e}. Using unity as default.")
351-
return 'unity'
352-
353-
def safe_file_format(model):
356+
logger.debug(
357+
f"Failed to parse catalog name from model: {e}. Using unity as default."
358+
)
359+
return "unity"
360+
361+
def safe_file_format(model: Any) -> Optional[str]:
354362
try:
355363
if is_unsupported_object(model):
356364
return None
357-
return safe_get(model, 'file_format')
365+
return safe_get(model, "file_format")
358366
except Exception as e:
359367
logger.debug(f"Failed to get file_format from model: {e}")
360368
return None
361-
362-
def safe_location_path(model):
369+
370+
def safe_location_path(model: Any) -> Optional[str]:
363371
try:
364372
if is_unsupported_object(model):
365373
return None
366-
if not hasattr(model, 'config') or not model.config:
374+
if not hasattr(model, "config") or not model.config:
367375
return None
368-
if model.config.get('include_full_name_in_path'):
376+
if model.config.get("include_full_name_in_path"):
369377
return f"{model.database}/{model.schema}/{model.identifier}"
370-
return model.identifier if hasattr(model, 'identifier') else None
378+
return model.identifier if hasattr(model, "identifier") else None
371379
except Exception as e:
372380
logger.debug(f"Failed to get location_path from model: {e}")
373381
return None
374-
375-
def safe_location_root(model):
382+
383+
def safe_location_root(model: Any) -> Optional[str]:
376384
try:
377385
if is_unsupported_object(model):
378386
return None
379-
return safe_get(model, 'location_root')
387+
return safe_get(model, "location_root")
380388
except Exception as e:
381389
logger.debug(f"Failed to get location_root from model: {e}")
382390
return None
383-
384-
def safe_table_format(model):
391+
392+
def safe_table_format(model: Any) -> Optional[str]:
385393
try:
386394
if is_unsupported_object(model):
387395
return None
388-
return safe_get(model, 'table_format')
396+
return safe_get(model, "table_format")
389397
except Exception as e:
390398
logger.debug(f"Failed to get table_format from model: {e}")
391399
return None
392-
393-
def safe_get(model, setting: str, case_sensitive=False):
400+
401+
def safe_get(
402+
model: Any, setting: str, case_sensitive: bool | None = False
403+
) -> str | None:
394404
try:
395405
if is_unsupported_object(model):
396406
return None
397407
# Check if model has config attribute
398-
if not hasattr(model, 'config') or not model.config:
408+
if not hasattr(model, "config") or not model.config:
399409
return None
400410
# Check if config has get method
401-
if not hasattr(model.config, 'get'):
411+
if not hasattr(model.config, "get"):
402412
return None
403413
value = model.config.get(setting)
404414
if value:
@@ -407,17 +417,17 @@ def safe_get(model, setting: str, case_sensitive=False):
407417
except Exception as e:
408418
logger.debug(f"Failed to get {setting} from model config: {e}")
409419
return None
410-
420+
411421
# Replace problematic functions with safe versions
412422
parse_model.catalog_name = safe_catalog_name
413423
parse_model.file_format = safe_file_format
414424
parse_model.location_path = safe_location_path
415425
parse_model.location_root = safe_location_root
416426
parse_model.table_format = safe_table_format
417427
parse_model._get = safe_get
418-
428+
419429
logger.debug("Applied dbt-databricks 1.10.2 compatibility patch")
420-
430+
421431
except ImportError:
422432
# parse_model module doesn't exist in older versions
423433
pass

0 commit comments

Comments
 (0)