rich icon indicating copy to clipboard operation
rich copied to clipboard

[BUG] Exception is not properly detected in Databricks

Open pstanisl opened this issue 2 years ago • 2 comments

If rich.traceback is installed (e.g., by a package like Kedro), the traceback of the error is, and string output for the cell in Databricks notebook, and the run is not interrupted.

The installed package (Kedro) used in our solution use rich.traceback. Therefore, putting the solution into production is impossible because the orchestration tool does not get an error output from the Databricks.

https://user-images.githubusercontent.com/1212845/183382098-d5831932-0e06-4c18-8c74-628cacc549c3.mov

Platform

Click to expand

Azure Databricks single node cluster

  • OS Linux
  • Python 3.8
  • Spark 3.2.1

Report output:

╭────────────────────── <class 'rich.console.Console'> ───────────────────────╮
│ A high level console interface.                                             │
│                                                                             │
│ ╭─────────────────────────────────────────────────────────────────────────╮ │
│ │ <console width=80 None>                                                 │ │
│ ╰─────────────────────────────────────────────────────────────────────────╯ │
│                                                                             │
│     color_system = None                                                     │
│         encoding = 'utf-8'                                                  │
│             file = <PythonShellImpl.ConsoleBuffer object at 0x7f0610722670> │
│           height = 25                                                       │
│    is_alt_screen = False                                                    │
│ is_dumb_terminal = False                                                    │
│   is_interactive = False                                                    │
│       is_jupyter = False                                                    │
│      is_terminal = False                                                    │
│   legacy_windows = False                                                    │
│         no_color = False                                                    │
│          options = ConsoleOptions(                                          │
│                        size=ConsoleDimensions(width=80, height=25),         │
│                        legacy_windows=False,                                │
│                        min_width=1,                                         │
│                        max_width=80,                                        │
│                        is_terminal=False,                                   │
│                        encoding='utf-8',                                    │
│                        max_height=25,                                       │
│                        justify=None,                                        │
│                        overflow=None,                                       │
│                        no_wrap=False,                                       │
│                        highlight=None,                                      │
│                        markup=None,                                         │
│                        height=None                                          │
│                    )                                                        │
│            quiet = False                                                    │
│           record = False                                                    │
│         safe_box = True                                                     │
│             size = ConsoleDimensions(width=80, height=25)                   │
│        soft_wrap = False                                                    │
│           stderr = False                                                    │
│            style = None                                                     │
│         tab_size = 8                                                        │
│            width = 80                                                       │
╰─────────────────────────────────────────────────────────────────────────────╯
╭─── <class 'rich._windows.WindowsConsoleFeatures'> ────╮
│ Windows features available.                           │
│                                                       │
│ ╭───────────────────────────────────────────────────╮ │
│ │ WindowsConsoleFeatures(vt=False, truecolor=False) │ │
│ ╰───────────────────────────────────────────────────╯ │
│                                                       │
│ truecolor = False                                     │
│        vt = False                                     │
╰───────────────────────────────────────────────────────╯
╭────── Environment Variables ───────╮
│ {                                  │
│     'TERM': 'unknown',             │
│     'COLORTERM': None,             │
│     'CLICOLOR': None,              │
│     'NO_COLOR': None,              │
│     'TERM_PROGRAM': None,          │
│     'COLUMNS': None,               │
│     'LINES': None,                 │
│     'JUPYTER_COLUMNS': None,       │
│     'JUPYTER_LINES': None,         │
│     'JPY_PARENT_PID': None,        │
│     'VSCODE_VERBOSE_LOGGING': None │
│ }                                  │
╰────────────────────────────────────╯
platform="Linux"

pstanisl avatar Aug 08 '22 09:08 pstanisl

The workaround is to save iPython._showtraceback before installing rich.traceback and then revert it after installing.

ip = get_ipython()
ip__showtraceback = ip._showtraceback

rich.traceback.install(...)

ip._showtraceback = ip__showtraceback

The workaround is crucial for me because a dependency is installing rich.traceback while importing it, i.e., it looks like this

ip = get_ipython()
ip__showtraceback = ip._showtraceback

from kedro.framework.startup import bootstrap_project

ip._showtraceback = ip__showtraceback

pstanisl avatar Aug 08 '22 10:08 pstanisl

I'm a maintainer of Kedro 🙂 We have a PR that would disable the rich.traceback.install call if the user is on Databricks: https://github.com/kedro-org/kedro/pull/1769

If this can't be fixed on the rich side then we can merge that, but if it is possible to get exception handling working correctly on Databricks that would be even better 🙏

Edit: @pstanisl please check the new issue here also: https://github.com/Textualize/rich/issues/2461

antonymilne avatar Aug 08 '22 14:08 antonymilne