Skip to content

Commit 10dede4

Browse files
committed
fixing tests
1 parent 63bf354 commit 10dede4

File tree

2 files changed

+12
-7
lines changed

2 files changed

+12
-7
lines changed

src/databricks/labs/ucx/framework/crawlers.py

Lines changed: 11 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -42,19 +42,24 @@ def _schema_for(cls, klass):
4242
return ", ".join(fields)
4343

4444
@classmethod
45-
def _filter_none_rows(cls, rows):
45+
def _filter_none_rows(cls, rows, full_name):
46+
if len(rows) == 0:
47+
return rows
48+
4649
results = []
47-
nullable_fields = []
50+
nullable_fields = set()
4851

4952
for field in dataclasses.fields(rows[0]):
5053
if field.default is None:
51-
nullable_fields.append(field.name)
54+
nullable_fields.add(field.name)
5255

5356
for row in rows:
57+
if row is None:
58+
continue
5459
row_contains_none = False
5560
for column, value in dataclasses.asdict(row).items():
5661
if value is None and column not in nullable_fields:
57-
logger.debug(f"Field {column} is None, filtering row")
62+
logger.warning(f"[{full_name}] Field {column} is None, filtering row")
5863
row_contains_none = True
5964
break
6065

@@ -81,7 +86,7 @@ def save_table(self, full_name: str, rows: list[any], mode="append"):
8186
if mode == "overwrite":
8287
msg = "Overwrite mode is not yet supported"
8388
raise NotImplementedError(msg)
84-
89+
rows = self._filter_none_rows(rows, full_name)
8590
if len(rows) == 0:
8691
return
8792

@@ -136,7 +141,7 @@ def fetch(self, sql) -> Iterator[any]:
136141
return self._spark.sql(sql).collect()
137142

138143
def save_table(self, full_name: str, rows: list[any], mode: str = "append"):
139-
rows = self._filter_none_rows(rows)
144+
rows = self._filter_none_rows(rows, full_name)
140145

141146
if len(rows) == 0:
142147
return

tests/unit/framework/test_crawlers.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -221,7 +221,7 @@ def test_runtime_backend_save_table_with_row_containing_none(mocker):
221221

222222
rb = RuntimeBackend()
223223

224-
rb.save_table("a.b.c", [Foo("aaa", True), Foo("bbb", False), Foo("bbb", None)])
224+
rb.save_table("a.b.c", [Foo("aaa", True), Foo("bbb", False), Foo("ccc", None)])
225225

226226
rb._spark.createDataFrame.assert_called_with(
227227
[Foo(first="aaa", second=True), Foo(first="bbb", second=False)],

0 commit comments

Comments
 (0)