Skip to content

Bug: <title>Litestar init() and AppConfig defaults aren't the same! #4296

@furioness

Description

@furioness

Description

I was creating my config and app factories with plain dicts, then I started to look for some annotated option and found that AppConfig dataclass - cool!

But my single test started to crash with some error on request_max_body_size and without normal console logging.

So here we are:

>>> from litestar.app import AppConfig
>>> from litestar import Litestar
>>> config = AppConfig()
... app1 = Litestar.from_config(config)
... app2 = Litestar()
>>> 
>>> app1.logging_config
>>> app2.logging_config
LoggingConfig(logging_module='logging', version=1,...)
>>>
>>> app1.request_max_body_size
<_EmptyEnum.EMPTY: 0>
>>> app2.request_max_body_size
10000000

So, with the help of AI, I identified the following discrepancies:

  • logging_config: LoggingConfig() vs None
  • response_cache_config: ResponseCacheConfig() vs None
  • openapi_config: DEFAULT_OPENAPI_CONFIG vs None
  • request_max_body_size: 10_000_000 vs Empty
  • on_app_init: [] vs None

Additionally, plain init starts by performing some mutation of the given arguments and then passes to the config.

if logging_config is Empty:
            logging_config = LoggingConfig()

        if debug is None:
            debug = os.getenv("LITESTAR_DEBUG", "0") == "1"

        if pdb_on_exception is None:
            pdb_on_exception = os.getenv("LITESTAR_PDB", "0") == "1"

config = AppConfig(
            after_exception=list(after_exception or []),
            after_request=after_request,
            ...)

URL to code causing the issue

No response

MCVE

Steps to reproduce

No response

Screenshots

No response

Logs


Litestar Version

2.17.0

Platform

  • Linux
  • Mac
  • Windows
  • Other (Please specify in the description above)

Metadata

Metadata

Assignees

No one assigned

    Labels

    Bug 🐛This is something that is not working as expected

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions