pytest-dev / pytest-dev/pluggy

Avoid erroring from tracing

Open
#424 4 comments 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

Dominant language
Python
Stars
1.7k
Forks
160
Avg merge
21h 4m
Merged PRs (30d)
6

Description

A user reported a weird condition in which pluggy tracing was making their code fail after we enabled tracing because one of the local objects didn't have a working __repr__ (a scikit-learn object from a very old version). Details: https://github.com/kedro-org/kedro/issues/2630

We gave the user a workaround and also it's reasonable to expect that objects have a working __repr__, but it would be nice if there was a generous try ... except around the tracing messages so that errors there don't bubble up. Essentially the same that happens with logging:

>>> try:
...   logging.warning("Will fail: %d", "a")
...   logging.warning("But the show must go on")
... except:
...   logging.error("Oh no")
... else:
...   logging.warning("Everything is fine")
... 
--- Logging error ---
Traceback (most recent call last):
  File "/opt/homebrew/Cellar/python@3.11/3.11.4/Frameworks/Python.framework/Versions/3.11/lib/python3.11/logging/__init__.py", line 1110, in emit
    msg = self.format(record)
          ^^^^^^^^^^^^^^^^^^^
  File "/opt/homebrew/Cellar/python@3.11/3.11.4/Frameworks/Python.framework/Versions/3.11/lib/python3.11/logging/__init__.py", line 953, in format
    return fmt.format(record)
           ^^^^^^^^^^^^^^^^^^
  File "/opt/homebrew/Cellar/python@3.11/3.11.4/Frameworks/Python.framework/Versions/3.11/lib/python3.11/logging/__init__.py", line 687, in format
    record.message = record.getMessage()
                     ^^^^^^^^^^^^^^^^^^^
  File "/opt/homebrew/Cellar/python@3.11/3.11.4/Frameworks/Python.framework/Versions/3.11/lib/python3.11/logging/__init__.py", line 377, in getMessage
    msg = msg % self.args
          ~~~~^~~~~~~~~~~
TypeError: %d format: a real number is required, not str
Call stack:
  File "<stdin>", line 2, in <module>
Message: 'Will fail: %d'
Arguments: ('a',)
WARNING:root:But the show must go on
WARNING:root:Everything is fine

Contributor guide

No contributing guide indexed for this repository

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Research direction

Start by locating pluggy's tracing implementation and the code that formats tracing messages; the issue does not name a file or test. Reproduce the failure with an object whose repr raises, then verify that tracing errors no longer propagate and normal application execution continues.

Written by the indexing model from the issue text.

Assessment

Tech stack
python
Domain
observability, tooling
Issue type
Bug
Difficulty
3/5
Estimated time
1-2 days
Activity status
Stale
Clarity
Mostly clear
Newbie friendliness
35/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.