Skip to content

AttributeError: 'FakeIPython' object has no attribute 'register_magic_function' #1096

@joshuasundance-swca

Description

@joshuasundance-swca

Expected Behavior

Solara runs as server app as reliably as it does in a notebook when imported code uses IPython.core.magic.register_cell_magic

Current Behavior

Code that calls from IPython.core.magic.register_cell_magic in a context that uses an instance of solara.server.patch.FakeIPython will result in the AttributeError in the title of this issue:

AttributeError: 'FakeIPython' object has no attribute 'register_magic_function'

Steps to Reproduce the Problem

  1. Write solara code that imports code that uses register_cell_magic, for example mermaid-py: from mermaid import Mermaid as seen below
  2. Observe that it works in a Jupyter notebook
  3. Observe that using solara run results in AttributeError

App with the following code fails with solara run but works in notebook:

import solara
from mermaid import Mermaid

Workaround

import solara.server.patch


# Patch the FakeIPython class to add register_magic_function
def noop_register_magic_function(self, *args, **kwargs):
    pass


# I looked at mermaid-py's use of register_magic_function and I don't need it
solara.server.patch.FakeIPython.register_magic_function = noop_register_magic_function

import solara
from mermaid import Mermaid

Specifications

  • Solara Version: 1.51.1

  • Platform: Docker on Windows python:3.13.7-slim-trixie

    • uname -a: Linux f6f919b954ee 6.6.87.2-microsoft-standard-WSL2 #1 SMP PREEMPT_DYNAMIC Thu Jun 5 18:30:46 UTC 2025 x86_64 GNU/Linux
  • Affected Python Versions: 3.13.7

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions