Skip to content

Commit

Permalink
Support a dataclass type as an argument
Browse files Browse the repository at this point in the history
  • Loading branch information
dmontagu committed May 3, 2024
1 parent 1ac2d9d commit ac5eae1
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 1 deletion.
2 changes: 1 addition & 1 deletion logfire/_internal/json_schema.py
Original file line number Diff line number Diff line change
Expand Up @@ -118,7 +118,7 @@ def create_json_schema(obj: Any, seen: set[int]) -> JsonDict:
return _mapping_schema(obj, seen)
elif is_sqlalchemy(obj):
return _sqlalchemy_schema(obj, seen)
elif dataclasses.is_dataclass(obj):
elif dataclasses.is_dataclass(obj) and not isinstance(obj, type):
return _dataclass_schema(obj, seen)
elif is_attrs(obj):
return _attrs_schema(obj, seen)
Expand Down
13 changes: 13 additions & 0 deletions tests/test_json_args.py
Original file line number Diff line number Diff line change
Expand Up @@ -809,6 +809,19 @@ class StrSubclass(str):
},
id='dict_of_types_in_list',
),
pytest.param(
[MyDataclass],
"[<class 'tests.test_json_args.MyDataclass'>]",
'["<class \'tests.test_json_args.MyDataclass\'>"]',
{
'items': {
'type': 'object',
'x-python-datatype': 'unknown',
},
'type': 'array',
},
id='list_of_dataclass_type',
),
],
)
def test_log_non_scalar_args(
Expand Down

0 comments on commit ac5eae1

Please sign in to comment.