Skip to content

Commit

Permalink
Fix export json related model (#837)
Browse files Browse the repository at this point in the history
  • Loading branch information
Vasiliy566 authored Oct 23, 2024
1 parent 278ab5a commit e5e366b
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 1 deletion.
2 changes: 1 addition & 1 deletion sqladmin/models.py
Original file line number Diff line number Diff line change
Expand Up @@ -1198,7 +1198,7 @@ async def generate() -> AsyncGenerator[str, None]:

for row in data:
row_dict = {
name: await self.get_prop_value(row, name)
name: str(await self.get_prop_value(row, name))
for name in self._export_prop_names
}
yield json.dumps(row_dict) + separator
Expand Down
16 changes: 16 additions & 0 deletions tests/test_views/test_view_sync.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import enum
import json
from typing import Any, Generator

import pytest
Expand Down Expand Up @@ -741,6 +742,21 @@ def test_export_json(client: TestClient) -> None:
assert response.text == '[{"name": "Daniel", "status": "ACTIVE"}]'


def test_export_json_complex_model(client: TestClient) -> None:
with session_maker() as session:
user = User(name="Daniel", status="ACTIVE")
session.add(user)
session.commit()
address = Address(user_id=user.id)
session.add(address)
session.commit()

response = client.get("/admin/address/export/json")
assert response.text == json.dumps(
[{"id": "1", "user_id": "1", "user": "User 1", "user.profile.id": "None"}]
)


def test_export_csv_row_count(client: TestClient) -> None:
def row_count(resp) -> int:
return resp.text.count("\r\n") - 1
Expand Down

0 comments on commit e5e366b

Please sign in to comment.