chore(data-quality): improve messaging for COUNT strategy failure (#18884)

This commit is contained in:
Imri Paran 2024-12-03 10:44:20 +01:00 committed by GitHub
parent 1140578b05
commit 416ba2c9cb
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194

View File

@ -37,7 +37,13 @@ class TableCustomSQLQueryValidator(BaseTableCustomSQLQueryValidator, SQAValidato
text(sql_expression)
)
if strategy == Strategy.COUNT:
return cursor.scalar()
result = cursor.scalar()
if not isinstance(result, int):
raise ValueError(
f"When using COUNT strategy, the result must be an integer. Received: {type(result)}\n"
"Example: SELECT COUNT(*) FROM table_name WHERE my_value IS NOT NULL"
)
return result
return cursor.fetchall()
except Exception as exc:
self.runner._session.rollback() # pylint: disable=protected-access