diff --git a/ormar/models/helpers/pydantic.py b/ormar/models/helpers/pydantic.py index 23372434c..b7d78a338 100644 --- a/ormar/models/helpers/pydantic.py +++ b/ormar/models/helpers/pydantic.py @@ -110,7 +110,7 @@ def get_pydantic_base_orm_config() -> pydantic.ConfigDict: :rtype: pydantic Config """ - return ConfigDict(validate_assignment=True) + return ConfigDict(validate_assignment=True, ser_json_bytes="base64") def get_potential_fields(attrs: Union[Dict, MappingProxyType]) -> Dict: diff --git a/tests/test_fastapi/test_binary_fields.py b/tests/test_fastapi/test_binary_fields.py index cd06831c9..0564216de 100644 --- a/tests/test_fastapi/test_binary_fields.py +++ b/tests/test_fastapi/test_binary_fields.py @@ -61,8 +61,7 @@ class BinaryThing(ormar.Model): id: uuid.UUID = ormar.UUID(primary_key=True, default=uuid.uuid4) name: str = ormar.Text(default="") - bt: str = ormar.Enum(enum_class=BinaryEnum, represent_as_base64_str=True, - ) + bt: str = ormar.LargeBinary(represent_as_base64_str=True, max_length=100) @app.get("/things", response_model=List[BinaryThing]) @@ -101,11 +100,6 @@ async def test_read_main(): def test_schema(): - schema = BinaryThing.schema() + schema = BinaryThing.model_json_schema() assert schema["properties"]["bt"]["format"] == "base64" - converted_choices = ["7g==", "/w==", "8CiMKA==", "wyg="] - assert len(schema["properties"]["bt"]["enum"]) == 4 - assert all( - choice in schema["properties"]["bt"]["enum"] for choice in converted_choices - ) assert schema["example"]["bt"] == "string" diff --git a/tests/test_fastapi/test_fastapi_usage.py b/tests/test_fastapi/test_fastapi_usage.py index 29a2ad9fe..7d7ad8466 100644 --- a/tests/test_fastapi/test_fastapi_usage.py +++ b/tests/test_fastapi/test_fastapi_usage.py @@ -55,7 +55,6 @@ async def test_read_main(): assert response.json() == { "category": { "id": None, - "items": [{"id": 1, "name": "test"}], "name": "test cat", }, "id": 1, @@ -63,3 +62,4 @@ async def test_read_main(): } item = Item(**response.json()) assert item.id == 1 + assert item.category.items[0].id == 1