Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Ability to parse UUID #15

Closed
deby22 opened this issue Apr 8, 2022 · 2 comments · Fixed by #23
Closed

Ability to parse UUID #15

deby22 opened this issue Apr 8, 2022 · 2 comments · Fixed by #23

Comments

@deby22
Copy link

deby22 commented Apr 8, 2022

def dup_key(query: t.Dict[str, t.Any]) -> t.Tuple[str, str]:
return (query["sql"], json.dumps(query["params"]))

Using UUID field raise an exception

*** TypeError: Object of type UUID is not JSON serializable

I suggest, adding UUID serialization, by cast to str

if isinstance(obj, UUID):
    return str(obj)

Or allow setting encoder on json.dumps method

@florimondmanca
Copy link

florimondmanca commented May 18, 2022

For anyone finding this issue, I bumped into the same situation and managed to find a workaround using FastAPI's jsonable_encoder:

from debug_toolbar.panels.sqlalchemy import SQLAlchemyPanel as Base
from fastapi.encoders import jsonable_encoder

class SQLAlchemyPanel(Base):
    def after_execute(self, *args) -> None:  # type: ignore
        # HACK: base SQL panel calls json.dumps(parameters) at some point.
        # Ensure values such as UUIDs can be dumped.
        parameters = args[3]
        args = (*args[:3], jsonable_encoder(parameters), *args[4:])
        return super().after_execute(*args)

It can then be used by passing panels=["path.to.panels.SQLAlchemyPanel"].

Not sure if this should be done by default.

@mongkok
Copy link
Owner

mongkok commented Dec 12, 2022

Hey @deby22 , issue is fixed using jsonable_encoder() as suggested by @florimondmanca , see #23 and v0.3.0.

@mongkok mongkok closed this as completed Dec 12, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging a pull request may close this issue.

3 participants