Skip to content
New issue

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

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

Already on GitHub? Sign in to your account

Bug: passing wrapper_class to StructLoggingConfig causes Pydantic exception #1948

Closed
1 of 4 tasks
kpetersen-rgare opened this issue Jul 13, 2023 · 4 comments
Closed
1 of 4 tasks
Assignees
Labels
1.x Bug This is something that is not working as expected in 1.x Bug 🐛 This is something that is not working as expected

Comments

@kpetersen-rgare
Copy link

kpetersen-rgare commented Jul 13, 2023

Description

When trying to hook up structlog to starlite v1.51.12, I got the Pydantic exception below on starting up the app. I tried the same with the litestar v2 beta hello-world app, and it worked. I realize this may not get fixed in v1.51.x. Is there a suggested workaround?

URL to code causing the issue

https://github.com/kpetersen-rgare/litestar-hello-world/blob/structlog-logging-config-bug/main.py

MCVE

# see URL to code

Steps to reproduce

1. clone MRE repo and `poetry install`
2. `poetry run uvicorn main:app`
3. See error

Screenshots

"![SCREENSHOT_DESCRIPTION](SCREENSHOT_LINK.png)"

Logs

Traceback (most recent call last):
  File "/Users/me/Library/Caches/pypoetry/virtualenvs/starlite-hello-world-cQlwT1sN-py3.11/bin/uvicorn", line 8, in <module>
    sys.exit(main())
             ^^^^^^
  File "/Users/me/Library/Caches/pypoetry/virtualenvs/starlite-hello-world-cQlwT1sN-py3.11/lib/python3.11/site-packages/click/core.py", line 1157, in __call__
    return self.main(*args, **kwargs)
           ^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/Users/me/Library/Caches/pypoetry/virtualenvs/starlite-hello-world-cQlwT1sN-py3.11/lib/python3.11/site-packages/click/core.py", line 1078, in main
    rv = self.invoke(ctx)
         ^^^^^^^^^^^^^^^^
  File "/Users/me/Library/Caches/pypoetry/virtualenvs/starlite-hello-world-cQlwT1sN-py3.11/lib/python3.11/site-packages/click/core.py", line 1434, in invoke
    return ctx.invoke(self.callback, **ctx.params)
           ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/Users/me/Library/Caches/pypoetry/virtualenvs/starlite-hello-world-cQlwT1sN-py3.11/lib/python3.11/site-packages/click/core.py", line 783, in invoke
    return __callback(*args, **kwargs)
           ^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/Users/me/Library/Caches/pypoetry/virtualenvs/starlite-hello-world-cQlwT1sN-py3.11/lib/python3.11/site-packages/uvicorn/main.py", line 410, in main
    run(
  File "/Users/me/Library/Caches/pypoetry/virtualenvs/starlite-hello-world-cQlwT1sN-py3.11/lib/python3.11/site-packages/uvicorn/main.py", line 578, in run
    server.run()
  File "/Users/me/Library/Caches/pypoetry/virtualenvs/starlite-hello-world-cQlwT1sN-py3.11/lib/python3.11/site-packages/uvicorn/server.py", line 61, in run
    return asyncio.run(self.serve(sockets=sockets))
           ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/usr/local/Cellar/python@3.11/3.11.4_1/Frameworks/Python.framework/Versions/3.11/lib/python3.11/asyncio/runners.py", line 190, in run
    return runner.run(main)
           ^^^^^^^^^^^^^^^^
  File "/usr/local/Cellar/python@3.11/3.11.4_1/Frameworks/Python.framework/Versions/3.11/lib/python3.11/asyncio/runners.py", line 118, in run
    return self._loop.run_until_complete(task)
           ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/usr/local/Cellar/python@3.11/3.11.4_1/Frameworks/Python.framework/Versions/3.11/lib/python3.11/asyncio/base_events.py", line 653, in run_until_complete
    return future.result()
           ^^^^^^^^^^^^^^^
  File "/Users/me/Library/Caches/pypoetry/virtualenvs/starlite-hello-world-cQlwT1sN-py3.11/lib/python3.11/site-packages/uvicorn/server.py", line 68, in serve
    config.load()
  File "/Users/me/Library/Caches/pypoetry/virtualenvs/starlite-hello-world-cQlwT1sN-py3.11/lib/python3.11/site-packages/uvicorn/config.py", line 473, in load
    self.loaded_app = import_from_string(self.app)
                      ^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/Users/me/Library/Caches/pypoetry/virtualenvs/starlite-hello-world-cQlwT1sN-py3.11/lib/python3.11/site-packages/uvicorn/importer.py", line 21, in import_from_string
    module = importlib.import_module(module_str)
             ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/usr/local/Cellar/python@3.11/3.11.4_1/Frameworks/Python.framework/Versions/3.11/lib/python3.11/importlib/__init__.py", line 126, in import_module
    return _bootstrap._gcd_import(name[level:], package, level)
           ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "<frozen importlib._bootstrap>", line 1204, in _gcd_import
  File "<frozen importlib._bootstrap>", line 1176, in _find_and_load
  File "<frozen importlib._bootstrap>", line 1147, in _find_and_load_unlocked
  File "<frozen importlib._bootstrap>", line 690, in _load_unlocked
  File "<frozen importlib._bootstrap_external>", line 940, in exec_module
  File "<frozen importlib._bootstrap>", line 241, in _call_with_frames_removed
  File "/Users/me/Developer/kpetersen-rgare/litestar-hello-world/main.py", line 19, in <module>
    logging_config = StructLoggingConfig(
                     ^^^^^^^^^^^^^^^^^^^^
  File "pydantic/main.py", line 341, in pydantic.main.BaseModel.__init__
pydantic.error_wrappers.ValidationError: 1 validation error for StructLoggingConfig
wrapper_class
  Protocols with non-method members don't support issubclass() (type=type_error)

Litestar Version

1.51.12

Platform

  • Linux
  • Mac
  • Windows
  • Other (Please specify in the description above)
@kpetersen-rgare kpetersen-rgare added Bug 🐛 This is something that is not working as expected Triage Required 🏥 This requires triage labels Jul 13, 2023
@JacobCoffee JacobCoffee added 1.x Bug This is something that is not working as expected in 1.x and removed Triage Required 🏥 This requires triage labels Jul 14, 2023
@JacobCoffee
Copy link
Member

Hi @kpetersen-rgare! Thanks for the report. We have squashed a few bugs around structlog issues and we should backport these.

edited: I am a bad reader and shouldnt answer issues so late 🙃

@kpetersen-rgare
Copy link
Author

kpetersen-rgare commented Jul 14, 2023

Hey, thanks for the quick response. I realized a simple workaround is to create my own structlog config class from the BaseLoggingConfig class that does not inherit from pydantic's BaseModel:

class MyStructLoggingConfig(BaseLoggingConfig):
    def configure(self) -> "GetLogger":
        structlog.configure(
            processors=processors,
            wrapper_class=structlog.make_filtering_bound_logger(logging.DEBUG),
            logger_factory=logger_factory,
        )
        return structlog.get_logger

@provinzkraut
Copy link
Member

@JacobCoffee can you take this one?

@Goldziher Goldziher assigned Goldziher and JacobCoffee and unassigned Goldziher Jul 23, 2023
@JacobCoffee
Copy link
Member

Hi yes, I will look into this starting tonight

JacobCoffee added a commit that referenced this issue Aug 4, 2023

Verified

This commit was signed with the committer’s verified signature.
mkniewallner Mathieu Kniewallner
…es pydantic exception (#2105)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
1.x Bug This is something that is not working as expected in 1.x Bug 🐛 This is something that is not working as expected
Projects
None yet
Development

No branches or pull requests

4 participants