Skip to content
This repository has been archived by the owner on Sep 12, 2023. It is now read-only.

Commit

Permalink
feat(plugin): set starlite debug
Browse files Browse the repository at this point in the history
  • Loading branch information
peterschutt committed Nov 17, 2022
1 parent 768d992 commit 1a9e01d
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 0 deletions.
17 changes: 17 additions & 0 deletions src/starlite_saqlalchemy/init_plugin.py
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,7 @@ def example_handler() -> dict:
openapi,
redis,
sentry,
settings,
sqlalchemy_plugin,
)
from starlite_saqlalchemy.health import health_check
Expand Down Expand Up @@ -132,6 +133,11 @@ class PluginConfig(BaseModel):
Configure the application to initialize Sentry on startup. Adds a handler to
[`AppConfig.on_startup`][starlite.config.app.AppConfig.on_startup].
"""
do_set_debug: bool = True
"""
Allow the plugin to set the starlite `debug` parameter. Parameter set to value of
[`AppConfig.debug`][starlite_saqlalchemy.settings.AppConfig.debug].
"""
do_sqlalchemy_plugin: bool = True
"""
Set the SQLAlchemy plugin on the application. Adds the plugin to
Expand Down Expand Up @@ -189,6 +195,7 @@ def __call__(self, app_config: AppConfig) -> AppConfig:
self.configure_cache(app_config)
self.configure_collection_dependencies(app_config)
self.configure_compression(app_config)
self.configure_debug(app_config)
self.configure_exception_handlers(app_config)
self.configure_health_check(app_config)
self.configure_logging(app_config)
Expand Down Expand Up @@ -248,6 +255,16 @@ def configure_compression(self, app_config: AppConfig) -> None:
if self.config.do_compression and app_config.compression_config is None:
app_config.compression_config = compression.config

def configure_debug(self, app_config: AppConfig) -> None:
"""Set Starlite's `debug` parameter.
Args:
app_config: The Starlite application config object.
"""

if self.config.do_set_debug:
app_config.debug = settings.app.DEBUG

def configure_exception_handlers(self, app_config: AppConfig) -> None:
"""Add the handlers that translate service and repository exceptions
into HTTP exceptions.
Expand Down
2 changes: 2 additions & 0 deletions tests/unit/test_init_plugin.py
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@ def test_config_switches() -> None:
do_openapi=False,
do_response_class=False,
do_sentry=False,
do_set_debug=False,
do_sqlalchemy_plugin=False,
do_worker=False,
)
Expand All @@ -40,6 +41,7 @@ def test_config_switches() -> None:
on_app_init=[init_plugin.ConfigureApp(config=config)],
)
assert app.compression_config is None
assert app.debug is False
assert app.logging_config is None
assert app.openapi_config is None
assert app.response_class is None
Expand Down

0 comments on commit 1a9e01d

Please sign in to comment.