Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Panel._compute_sizing_mode not gracefully handling None #6265

Closed
1 task done
banesullivan-kobold opened this issue Jan 23, 2024 · 1 comment · Fixed by #6267
Closed
1 task done

Panel._compute_sizing_mode not gracefully handling None #6265

banesullivan-kobold opened this issue Jan 23, 2024 · 1 comment · Fixed by #6267

Comments

@banesullivan-kobold
Copy link

ALL software version info

(this library, plus any other relevant software, e.g. bokeh, python, notebook, OS, browser, etc)

--------------------------------------------------------------------------------
  Date: Tue Jan 23 17:55:49 2024 GMT

                OS : Linux
            CPU(s) : 12
           Machine : aarch64
      Architecture : 64bit
               RAM : 23.4 GiB
       Environment : Python

  Python 3.10.13 (main, Oct 12 2023, 02:03:44) [GCC 12.2.0]

             panel : 1.3.7
             bokeh : 3.3.1
             numpy : 1.23.5
             scipy : 1.10.1
           IPython : 8.12.0
        matplotlib : 3.7.1
            scooby : 0.8.0
--------------------------------------------------------------------------------

Description of expected behavior and the observed behavior

Panel._compute_sizing_mode is not gracefully handling if margin is set as None in the passed props.

Complete, minimal, self-contained example code that reproduces the issue

I am struggling to make a MRE for this as this quirk/bug surfaced after some seemingly innocuous changes to other parts of a larger Panel application I'm working on. I cannot seem to track down exactly why the margin is being set to None with the pn.Row that is causing this.

I'm hoping that adding a check to make sure the margin is not None in this function is easy enough without tracking down the root cause though I also would love to get to the bottom of why the margin in the passed props to this function would ever be None.

Confirmed that self.margin has a value of 0, but that the passed props has margin of None which is preferred here:

margin = props.get('margin', self.margin)

Stack traceback and/or browser JavaScript console output

  File "/python/lib/python3.10/site-packages/panel/layout/base.py", line 511, in pop
    self.objects = new_objects
  File "/python/lib/python3.10/site-packages/param/parameterized.py", line 525, in _f
    instance_param.__set__(obj, val)
  File "/python/lib/python3.10/site-packages/param/parameterized.py", line 527, in _f
    return f(self, obj, val)
  File "/python/lib/python3.10/site-packages/param/parameterized.py", line 1545, in __set__
    obj.param._call_watcher(watcher, event)
  File "/python/lib/python3.10/site-packages/param/parameterized.py", line 2486, in _call_watcher
    self_._execute_watcher(watcher, (event,))
  File "/python/lib/python3.10/site-packages/param/parameterized.py", line 2468, in _execute_watcher
    watcher.fn(*args, **kwargs)
  File "/python/lib/python3.10/site-packages/panel/reactive.py", line 374, in _param_change
    self._apply_update(named_events, properties, model, ref)
  File "/python/lib/python3.10/site-packages/panel/reactive.py", line 302, in _apply_update
    self._update_model(events, msg, root, model, doc, comm)
  File "/python/lib/python3.10/site-packages/panel/layout/base.py", line 99, in _update_model
    msg.update(self._compute_sizing_mode(
  File "/python/lib/python3.10/site-packages/panel/layout/base.py", line 241, in _compute_sizing_mode
    width += margin*2
TypeError: unsupported operand type(s) for *: 'NoneType' and 'int'

Screenshots or screencasts of the bug in action

  • I may be interested in making a pull request to address this

My current solution is to just monkey patch Panel._compute_sizing_mode with:

from panel.layout.base import Panel

_panel_compute_sizing_mode = Panel._compute_sizing_mode


def _compute_sizing_mode(self, children, props):
    if props.get("margin", self.margin) is None:
        props["margin"] = 0
    return _panel_compute_sizing_mode(self, children, props)


Panel._compute_sizing_mode = _compute_sizing_mode

(in my app, I actually apply the entire function copy/pasted to ensure this is thread safe, but the above is the spirit of it)

@philippjfr
Copy link
Member

@banesullivan-kobold Thanks for tracking this down, I'd love to get the fix for this into the 1.3.8 release I'm planning for today. If you get a chance today I'd love to see a PR, but if you're in a time crunch I plan to make a PR myself and then release it.

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 a pull request may close this issue.

2 participants