Skip to content
New issue

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

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

Already on GitHub? # to your account

[BUG]: passing ORJSONResponse double encodes the response #436

Open
jjfantini opened this issue Jul 26, 2024 · 1 comment
Open

[BUG]: passing ORJSONResponse double encodes the response #436

jjfantini opened this issue Jul 26, 2024 · 1 comment
Labels
bug Something isn't working help wanted Extra attention is needed needs-triage Needs to be reviewed

Comments

@jjfantini
Copy link

jjfantini commented Jul 26, 2024

I cannot pass a direct FastAPI response like JSON/ORJSONResponse as an output for the FastAPI route; when I do, the first response is correct, but then the first cache HIT is double encoded.

Setup

    redis = await aioredis.Redis(
        host="localhost",
        port=6379,
        db=1,
        decode_responses=False,
    )
    FastAPICache.init(RedisBackend(redis), prefix="fastapi-cache")

The double encoded data comes if the return object is like:

return ORJSONResponse(content=result)

The result object is a list of dicts result = lf.collect().to_dicts(). This turns a LazyFrame into a list of dicts list[dict[str, Any]] .

If I pass the object directly then it works, but how can I pass the direct response, to bypass FastAPIs encoding or passing the custom ORJSONResponse so that the encoding engine uses orjson and not just json

@vicchi
Copy link
Collaborator

vicchi commented Nov 9, 2024

@jjfantini Can you knock up a reproducible test case for this please?

@vicchi vicchi added bug Something isn't working help wanted Extra attention is needed needs-triage Needs to be reviewed labels Nov 9, 2024
# for free to join this conversation on GitHub. Already have an account? # to comment
Labels
bug Something isn't working help wanted Extra attention is needed needs-triage Needs to be reviewed
Projects
None yet
Development

No branches or pull requests

2 participants