Open
Description
Thanks for this great project. It is really helpful and simplifies the migration from django to fastapi.
I use SQLAlchemyPanel and have a mysql table with a binary column described by:
filedata: Mapped[bytes] = mapped_column(LONGBLOB)
When updating this column with binary data, I receive the following error
UnicodeDecodeError: 'utf-8' codec can't decode byte 0x9d in position 15: invalid start byte
Traceback is
File "[..].venv/lib/python3.11/site-packages/debug_toolbar/panels/sqlalchemy.py", line 44, in after_execute
self.add_query(str(context.engine.url), query)
File "[..].venv/lib/python3.11/site-packages/debug_toolbar/panels/sql.py", line 110, in add_query
self._queries.append((alias, jsonable_encoder(query)))
^^^^^^^^^^^^^^^^^^^^^^^
File "[..].venv/lib/python3.11/site-packages/fastapi/encoders.py", line 289, in jsonable_encoder
encoded_value = jsonable_encoder(
^^^^^^^^^^^^^^^^^
File "[..].venv/lib/python3.11/site-packages/fastapi/encoders.py", line 303, in jsonable_encoder
jsonable_encoder(
File "[..].venv/lib/python3.11/site-packages/fastapi/encoders.py", line 289, in jsonable_encoder
encoded_value = jsonable_encoder(
^^^^^^^^^^^^^^^^^
File "[..].venv/lib/python3.11/site-packages/fastapi/encoders.py", line 318, in jsonable_encoder
return ENCODERS_BY_TYPE[type(obj)](obj)
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
File "[..].venv/lib/python3.11/site-packages/fastapi/encoders.py", line 59, in <lambda>
bytes: lambda o: o.decode(),
^^^^^^^^^^
UnicodeDecodeError: 'utf-8' codec can't decode byte 0x9d in position 15: invalid start byte
A simplified example for a fastapi endpoint is
@router.get("/test_binary/")
def test_binary(session: Session = Depends(create_session)):
import io
import xlsxwriter
xlb = io.BytesIO()
workbook = xlsxwriter.Workbook(xlb)
worksheet = workbook.add_worksheet("Test")
worksheet.name = 'Worksheet'
workbook.close()
export = session.query(BinaryTable).filter([..]).first()
export.filedata = xlb.getvalue()
session.commit()
It seems that the bytes parameter cannot be logged.
Used versions:
- fastapi==0.111.0
- fastapi-debug-toolbar==0.6.3
- sqlalchemy==2.0.30
- xlsxwriter==3.2.0
Metadata
Metadata
Assignees
Labels
No labels