Skip to content

Commit

Permalink
Fix pydantic tests again (#582)
Browse files Browse the repository at this point in the history
Co-authored-by: sydney-runkle <[email protected]>
  • Loading branch information
alexmojaki and sydney-runkle authored Nov 12, 2024
1 parent 632ad7f commit 15ff969
Show file tree
Hide file tree
Showing 3 changed files with 112 additions and 109 deletions.
2 changes: 1 addition & 1 deletion logfire/_internal/json_schema.py
Original file line number Diff line number Diff line change
Expand Up @@ -68,7 +68,7 @@ def type_to_schema() -> dict[type[Any], JsonDict | Callable[[Any, set[int]], Jso
pydantic.NameEmail: {'type': 'string', 'x-python-datatype': 'NameEmail'},
pydantic.SecretStr: {'type': 'string', 'x-python-datatype': 'SecretStr'},
pydantic.SecretBytes: {'type': 'string', 'x-python-datatype': 'SecretBytes'},
pydantic.AnyUrl: {'type': 'string', 'x-python-datatype': 'Url'},
pydantic.AnyUrl: {'type': 'string', 'x-python-datatype': 'AnyUrl'},
pydantic.BaseModel: _pydantic_model_schema,
}
)
Expand Down
11 changes: 7 additions & 4 deletions tests/test_json_args.py
Original file line number Diff line number Diff line change
Expand Up @@ -156,6 +156,9 @@ class StrSubclass(str):
pass


ANYURL_REPR_CLASSNAME = repr(AnyUrl('http://test.com')).split('(')[0]


@pytest.mark.parametrize(
'value,value_repr,value_json,json_schema',
[
Expand Down Expand Up @@ -489,26 +492,26 @@ class StrSubclass(str):
),
pytest.param(
MyModel(x='x', y=10, u=AnyUrl('http://test.com')),
"x='x' y=10 u=Url('http://test.com/')",
f"x='x' y=10 u={ANYURL_REPR_CLASSNAME}('http://test.com/')",
'{"x":"x","y":10,"u":"http://test.com/"}',
{
'type': 'object',
'title': 'MyModel',
'x-python-datatype': 'PydanticModel',
'properties': {'u': {'type': 'string', 'x-python-datatype': 'Url'}},
'properties': {'u': {'type': 'string', 'x-python-datatype': ANYURL_REPR_CLASSNAME}},
},
id='pydantic_model',
),
pytest.param(
MyModel.model_validate(dict(x='x', y=10, u='http://test.com', extra_key=MyDataclass(10))),
"x='x' y=10 u=Url('http://test.com/')",
f"x='x' y=10 u={ANYURL_REPR_CLASSNAME}('http://test.com/')",
'{"x":"x","y":10,"u":"http://test.com/","extra_key":{"t":10}}',
{
'type': 'object',
'title': 'MyModel',
'x-python-datatype': 'PydanticModel',
'properties': {
'u': {'type': 'string', 'x-python-datatype': 'Url'},
'u': {'type': 'string', 'x-python-datatype': ANYURL_REPR_CLASSNAME},
'extra_key': {
'type': 'object',
'title': 'MyDataclass',
Expand Down
Loading

0 comments on commit 15ff969

Please sign in to comment.