#Any ideas on how to get around the printing all the binary data on errors issue for version 1.51.x?

1 messages · Page 1 of 1 (latest)

ruby sedge
#

so the problem has been solved for the 2.0.0 release:
https://github.com/starlite-api/starlite/pull/1296

and it sounds like making a backfix is pretty difficult.
So i am open to any hacky fixes that can be thought of. It is making it extremely hard to debug endpoints as a lot of mine do deal with large binary data objects and i do make a lot of mistakes when coding lol.

GitHub

PR Checklist

Have you followed the guidelines in CONTRIBUTING.rst?
Have you got 100% test coverage on new code?
Have you updated the prose documentation?
Have you updated the reference documen...

rocky musk
#

Why not switch to the alpha?

ruby sedge
#

I think it was mentioned that it would have a lot of breaking changes between the alpha release and official release. I am fine switching to it if there is an expectation that it is production ready and only a few hours worth of work fixing breaking changes

rocky musk
#

Well, you should wait to the beta then

ruby sedge
#

is there a timeline on when that is?

ruby sedge
#

Is there a way to turn off logging just for those endpoints even? Part of the issue is even when there is an expected issue (raise NotAuthorizedException), I get a giant log that obfuscates all other logs

rocky musk
#

Don't run in debug mode

#

It will turn off exception logging

#

It's that simple

ruby sedge
#

So as far as i can tell i am not running the app in debug mode. This is what i have on boot:

plugin_config = PluginConfig(
    do_logging=True,
    do_after_exception=False,
    do_cache=False,
    do_compression=False,
    do_collection_dependencies=False,
    do_exception_handlers=False,
    do_health_check=False,
    do_openapi=False,
    do_sentry=False,
    do_set_debug=False,
    do_sqlalchemy_plugin=True,
    do_type_encoders=False,
    do_worker=False,
)


def run_app() -> Starlite:
    logger.info("starting server")
    app = Starlite(
        after_exception=[exceptions.after_exception_hook_handler],
        cache_config=cache.config,
        compression_config=compression.config,
        cors_config=cors.cors_config,
        # not needed if jwt cookie uses sameSite=lax/strict
        # csrf_config=csrf.csrf_config,
        dependencies=dependencies,
        exception_handlers={
            RepositoryException: exceptions.repository_exception_to_http_response,
            ServiceException: exceptions.service_exception_to_http_response,
        },
        # logging_config=logging.CustomConfigureApp,
        openapi_config=openapi.config,
        route_handlers=[health_check, router],
        # plugins=[SQLAlchemyPlugin(config=sqlalchemy_plugin.config)],
        on_shutdown=[
            kafka_consumer.on_app_stop,
            kafka_producer.on_app_stop,
            redis.close,
            s3_client.close,
        ],
        on_startup=[
            sentry.configure,
            get_redis_connection,
            kafka_producer.on_app_start,
            kafka_consumer.on_app_start,
        ],
        static_files_config=static_files.config,
        type_encoders=type_encoders_map,
        on_app_init=[CustomConfigureApp(plugin_config), auth.jwt_cookie_auth.on_app_init],
    )
    return app
rocky musk
#

Hmm, weird.

@gentle meadow might have more insight here

ruby sedge
#

okay I think i have found a way to do this!
So my code uses the startkit as a starting point and looking at these two blocks of code:
https://github.com/starlite-api/starlite-pg-redis-docker/blob/main/app/main.py#L48

https://github.com/starlite-api/starlite-pg-redis-docker/blob/main/app/lib/exceptions.py#L38-L51

if i inspect the scope dict:

    if "_body" in scope and hasattr(scope["_body"], "__len__") and len(scope["_body"]) > 1000:
        logged_scope = {**scope, "_body": "REDACTED: body too large"}
    else:
        logged_scope = scope

I am able to modify the logged scope to a have a different _body. I think what i am doing is kosher.