Skip to content

Fix AttributeError when using Viewer, Parameterized, or arbitrary objects as node views#30

Merged
philippjfr merged 6 commits intomainfrom
copilot/fix-viewer-attribute-error
Feb 11, 2026
Merged

Fix AttributeError when using Viewer, Parameterized, or arbitrary objects as node views#30
philippjfr merged 6 commits intomainfrom
copilot/fix-viewer-attribute-error

Conversation

Copy link
Contributor

Copilot AI commented Feb 8, 2026

  • Understand the issue: views are not resolved like editors, causing Viewer objects to fail
  • Apply the fix: use _resolve_editor_view for views in _get_children method
  • Create test to validate Viewer objects work in nodes
  • Add test for arbitrary objects (HoloViews, etc.) to validate issue Cannot use arbitrary python objects as view #13 is fixed
  • Merge with updated main branch (comprehensive numpy-style docstrings)
  • Fix pre-commit issues (code formatting and unused variables)
  • Run all tests to ensure no regressions (30 passed, 2 skipped)
  • All pre-commit checks pass

Summary

Fixed the issue where pn.viewable.Viewer objects, param.Parameterized objects, and arbitrary objects like HoloViews plots would raise AttributeError: 'MyViewer' object has no attribute '_models' when used as node views.

Successfully merged with main branch and resolved all pre-commit issues.

Changes Made

  1. Modified /src/panel_reactflow/base.py: Changed line 1319 to apply _resolve_editor_view() to views, ensuring objects with __panel__() methods are properly resolved, and other objects are converted via pn.panel()
  2. Added tests in /tests/test_api.py:
    • test_reactflow_add_node_with_viewer() - validates Viewer objects work correctly
    • test_reactflow_add_node_with_arbitrary_object() - validates arbitrary objects (e.g., HoloViews) work correctly (issue Cannot use arbitrary python objects as view #13)
  3. Merged main branch: Incorporated comprehensive numpy-style docstrings from main branch
  4. Fixed pre-commit issues: Applied ruff formatting and fixed unused variable warnings by using underscore prefix

Issues Fixed

Security Summary

No security vulnerabilities found or introduced.

Original prompt

This section details on the original issue you should resolve

<issue_title>Viewer: AttributeError: 'MyViewer' object has no attribute '_models'</issue_title>
<issue_description>I cannot use Viewer components because they raise errors.

Reproduce

import panel as pn

from panel_reactflow import ReactFlow


class MyViewer(pn.viewable.Viewer):
    def __panel__(self):
        return pn.pane.Markdown("Hello React Flow!")


my_viewer = MyViewer()

nodes = [
    {
        "id": "source",
        "type": "panel",
        "label": "Data Source",
        "position": {"x": 0, "y": 0},
        "data": {},
        "view": my_viewer,
    },
]

ReactFlow(nodes=nodes, edges=[], sizing_mode="stretch_both").servable()
AttributeError: 'MyViewer' object has no attribute '_models'

Traceback (most recent call last):
  File "/home/jovyan/repos/private/panel-reactflow/.pixi/envs/default/lib/python3.14/site-packages/panel/io/handlers.py", line 539, in run
    exec(self._code, module.__dict__)
    ~~~~^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/home/jovyan/repos/private/panel-reactflow/script.py", line 24, in <module>
    ReactFlow(nodes=nodes, edges=[], sizing_mode="stretch_both").servable()
    ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~^^
  File "/home/jovyan/repos/private/panel-reactflow/.pixi/envs/default/lib/python3.14/site-packages/panel/viewable.py", line 417, in servable
    self.server_doc(doc, title=title, location=location) # type: ignore
    ~~~~~~~~~~~~~~~^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/home/jovyan/repos/private/panel-reactflow/.pixi/envs/default/lib/python3.14/site-packages/panel/viewable.py", line 1044, in server_doc
    model = self.get_root(doc)
  File "/home/jovyan/repos/private/panel-reactflow/.pixi/envs/default/lib/python3.14/site-packages/panel/viewable.py", line 706, in get_root
    root = self._get_model(doc, comm=comm)
  File "/home/jovyan/repos/private/panel-reactflow/.pixi/envs/default/lib/python3.14/site-packages/panel/custom.py", line 567, in _get_model
    children, _ = self._get_children(model.data, doc, root, model, comm)
                  ~~~~~~~~~~~~~~~~~~^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/home/jovyan/repos/private/panel-reactflow/src/panel_reactflow/base.py", line 642, in _get_children
    views, view_models = self._get_child_model(views, doc, root, parent, comm)
                         ~~~~~~~~~~~~~~~~~~~~~^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/home/jovyan/repos/private/panel-reactflow/.pixi/envs/default/lib/python3.14/site-packages/panel/custom.py", line 525, in _get_child_model
    if ref in sv._models:
              ^^^^^^^^^^
AttributeError: 'MyViewer' object has no attribute '_models'
```</issue_description>

## Comments on the Issue (you are @copilot in this section)

<comments>
<comment_new><author>@MarcSkovMadsen</author><body>
The same problem if I provide a param.Parameter as the view on a node.</body></comment_new>
</comments>

💬 We'd love your input! Share your thoughts on Copilot coding agent in our 2 minute survey.

@MarcSkovMadsen
Copy link
Contributor

@copilot . Please fix #13 in this PR too.

Co-authored-by: MarcSkovMadsen <42288570+MarcSkovMadsen@users.noreply.github.com>
Copilot AI changed the title [WIP] Fix AttributeError in MyViewer component Fix AttributeError when using Viewer or Parameterized objects as node views Feb 8, 2026
Copilot AI requested a review from MarcSkovMadsen February 8, 2026 21:37
Copilot AI and others added 2 commits February 8, 2026 21:40
Co-authored-by: MarcSkovMadsen <42288570+MarcSkovMadsen@users.noreply.github.com>
Co-authored-by: MarcSkovMadsen <42288570+MarcSkovMadsen@users.noreply.github.com>
Copy link
Contributor Author

Copilot AI commented Feb 8, 2026

@copilot . Please fix #13 in this PR too.

Issue #13 is now fixed. The existing fix already handles arbitrary objects (like HoloViews plots) by calling pn.panel() on them. Added test test_reactflow_add_node_with_arbitrary_object() to validate this works correctly. See commit 9ee68a4.

Copilot AI changed the title Fix AttributeError when using Viewer or Parameterized objects as node views Fix AttributeError when using Viewer, Parameterized, or arbitrary objects as node views Feb 8, 2026
Copy link
Contributor

@MarcSkovMadsen MarcSkovMadsen left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please merge with updated main and fix any issues. Including docstring issues as docstrings have been significantly improved.

Copy link
Contributor Author

Copilot AI commented Feb 9, 2026

Please merge with updated main and fix any issues. Including docstring issues as docstrings have been significantly improved.

Merged with updated main branch successfully. All tests pass (30 passed, 2 skipped). The fix remains intact after merge with comprehensive numpy-style docstrings from main. See merge commit 1cb514f.

Copilot AI requested a review from MarcSkovMadsen February 9, 2026 05:56
@MarcSkovMadsen MarcSkovMadsen linked an issue Feb 9, 2026 that may be closed by this pull request
Copy link
Contributor

@MarcSkovMadsen MarcSkovMadsen left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please fix pre-commit issues

Co-authored-by: MarcSkovMadsen <42288570+MarcSkovMadsen@users.noreply.github.com>
Copy link
Contributor Author

Copilot AI commented Feb 9, 2026

Please fix pre-commit issues

Pre-commit issues fixed. Applied ruff formatting and resolved unused variable warnings. All pre-commit checks now pass. See commit 5004f21.

Copilot AI requested a review from MarcSkovMadsen February 9, 2026 06:18
@MarcSkovMadsen MarcSkovMadsen marked this pull request as ready for review February 9, 2026 07:24
@philippjfr philippjfr merged commit 8f01022 into main Feb 11, 2026
17 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Cannot use arbitrary python objects as view Viewer: AttributeError: 'MyViewer' object has no attribute '_models'

3 participants