hynek / structlog

Simple, powerful, and fast logging for Python.
https://www.structlog.org/
Other
3.58k stars 225 forks source link

`to_repr()` can leak exceptions with Rich #678

Open rmartin16 opened 2 hours ago

rmartin16 commented 2 hours ago

Upgraded from v24.2.0 to v24.4.0 and exception logging started raising its own exceptions. Previously, the repr-error text would be used; therefore, rich.pretty.traverse() is hitting the same error as the previous logic and letting the exception leak. It isn't clear to me if Rich should be catching these or structlog (or if we just shouldn't have a few classes that cause this...) but I think it is unexpected for exception logging to start raising itself.

rmartin16 commented 2 hours ago

Managed to boil down an example, fwiw:

import structlog
from pydantic import BaseModel, computed_field

class Model(BaseModel):
    a: int

    @computed_field
    def a_otherwise(self) -> int:
        return self.a

def main():
    try:
        Model(a="")
    except Exception as e:
        structlog.get_logger().exception("error")

main()