From 815d173890b0b523ff6586abf854a6cd9a2d7169 Mon Sep 17 00:00:00 2001 From: Eric Vergnaud Date: Fri, 9 Aug 2024 17:45:24 +0200 Subject: [PATCH 1/2] work around Python reflection issue --- src/databricks/labs/lsql/backends.py | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/src/databricks/labs/lsql/backends.py b/src/databricks/labs/lsql/backends.py index 3c230e80..435f41c1 100644 --- a/src/databricks/labs/lsql/backends.py +++ b/src/databricks/labs/lsql/backends.py @@ -70,6 +70,13 @@ def _schema_for(cls, klass: Dataclass): fields = [] for f in dataclasses.fields(klass): field_type = f.type + # workaround rare (Python?) issue where f.type is the type name instead of the type itself + # this seems to happen when the dataclass is first used from a file importing it + if isinstance(field_type, str): + try: + field_type = __builtins__[field_type] + except: + logger.warning(f"Could not load type {field_type}") if isinstance(field_type, UnionType): field_type = field_type.__args__[0] if field_type not in cls._builtin_type_mapping: From fea6debd57dce8de3f38e11386f7be4c58bbec4b Mon Sep 17 00:00:00 2001 From: Eric Vergnaud Date: Tue, 27 Aug 2024 16:28:03 +0200 Subject: [PATCH 2/2] formatting --- src/databricks/labs/lsql/backends.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/databricks/labs/lsql/backends.py b/src/databricks/labs/lsql/backends.py index 435f41c1..4d32fb9a 100644 --- a/src/databricks/labs/lsql/backends.py +++ b/src/databricks/labs/lsql/backends.py @@ -75,8 +75,8 @@ def _schema_for(cls, klass: Dataclass): if isinstance(field_type, str): try: field_type = __builtins__[field_type] - except: - logger.warning(f"Could not load type {field_type}") + except TypeError as e: + logger.warning(f"Could not load type {field_type}", exc_info=e) if isinstance(field_type, UnionType): field_type = field_type.__args__[0] if field_type not in cls._builtin_type_mapping: