Skip to content

Commit e5609c2

Browse files
committed
isdataclass check in JsonSerializableMixin
Signed-off-by: Sai Shree Pradhan <saishree.pradhan@databricks.com>
1 parent cac7533 commit e5609c2

File tree

1 file changed

+6
-2
lines changed

1 file changed

+6
-2
lines changed

src/databricks/sql/telemetry/utils.py

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,7 @@
11
import json
22
from enum import Enum
3-
from dataclasses import asdict
3+
from dataclasses import asdict, is_dataclass
44
from abc import ABC
5-
from typing import Any
65

76

87
class JsonSerializableMixin(ABC):
@@ -13,6 +12,11 @@ def to_json(self) -> str:
1312
Convert the object to a JSON string, excluding None values.
1413
Handles Enum serialization and filters out None values from the output.
1514
"""
15+
if not is_dataclass(self):
16+
raise TypeError(
17+
f"{self.__class__.__name__} must be a dataclass to use JsonSerializableMixin"
18+
)
19+
1620
return json.dumps(
1721
asdict(
1822
self,

0 commit comments

Comments
 (0)