litestar-org / litestar

Production-ready, Light, Flexible and Extensible ASGI API framework | Effortlessly Build Performant APIs
https://litestar.dev/
MIT License
5.62k stars 382 forks source link

Bug: Structlog example no longer works #1008

Closed ste-pool closed 1 year ago

ste-pool commented 1 year ago

Me again. Sorry 🙈

Describe the bug Running the structlog example here results in an internal server error as of v1.45 (I think)

{"status_code":500,"detail":"TypeError(\"encode_json() got an unexpected keyword argument 'default'\")"}

The default encoder was changed here Which doesn't accept the default argument given here

I'm not sure if it's a structlog problem or a starlite problem.

Maybe the solution is to rename enc_hook to default then it mirrors the signature of json.dumps? I'm not sure, to be honest.

To Reproduce Run the structlog example in the documentation:

from starlite import Starlite, StructLoggingConfig, Request, get

@get("/")
def my_router_handler(request: Request) -> None:
    request.logger.info("inside a request")
    return None

logging_config = StructLoggingConfig()

app = Starlite(route_handlers=[my_router_handler], logging_config=logging_config)

Additional context Add any other context about the problem here.

provinzkraut commented 1 year ago

Me again. Sorry :see_no_evil:

Don't be, every bug report is very welcome!

Maybe the solution is to rename enc_hook to default then it mirrors the signature of json.dumps

Yes, that would be the best solution. Wanna add a PR?

This also definitely should have been caught by our tests.

vtarchon commented 1 year ago

This seems to be a regression at least since 2.0.0

https://github.com/litestar-org/litestar/blob/v2.0.0/litestar/serialization/msgspec_hooks.py#L127

I'm seeing the same error when using msgspec encoder over the default json.dumps