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

BUG: Defaults.grid_option dict instance is shared across widget instances #338

Open
hickmanw opened this issue Oct 6, 2020 · 0 comments · May be fixed by #339
Open

BUG: Defaults.grid_option dict instance is shared across widget instances #338

hickmanw opened this issue Oct 6, 2020 · 0 comments · May be fixed by #339

Comments

@hickmanw
Copy link

hickmanw commented Oct 6, 2020

Environment

You won't need this. I show below the lines of code that cause the issue.
Versions

python : 3.6.7.final.0
python-bits : 64
OS : Linux
OS-release : 4.14.193-149.317.amzn2.x86_64
machine : x86_64
processor : x86_64
qgrid :1.3.1
notebook: 6.1.3
jupyterlab:2.2.0
jupyterlab-launcher:0.13.1
jupyterlab-pygments:0.1.1
jupyterlab-server:1.2.0

Jupyter lab packages

@bokeh/jupyter_bokeh v2.0.3 enabled OK
@jupyter-widgets/jupyterlab-manager v2.0.0 enabled OK
@jupyterlab/hub-extension v2.2.0 enabled OK
@pyviz/jupyterlab_pyviz v1.0.4 enabled OK
jupyterlab-drawio v0.7.0 enabled OK
qgrid2 v1.1.3 enabled OK

Description of Issue

Widgets created using show_grid without specifying grid_options share a grid_option dict instance, such that changing an option for one will change it for the others.

Reproduction Steps

This will happen for any grid_option item.

In  [2]: grid1 = qgrid.show_grid(pd.DataFrame({'a':[1]}))
         grid2 = qgrid.show_grid(pd.DataFrame({'c':[5]}))
         grid1.grid_options["maxVisibleRows"]
Out [2]: 15

In  [3]: grid2.grid_options["maxVisibleRows"]
Out [3]: 15

In  [4]: grid1.change_grid_option("maxVisibleRows", 9)
         grid1.grid_options["maxVisibleRows"]
Out [4]: 9

In  [5]: grid2.grid_options["maxVisibleRows"]
Out [5]: 9

What steps have you taken to resolve this already?

This happens because new qgrid widgets instances are assigned the default grid_options dict, not a copy of that dict, within show_grid(), if the call doesn't include an argument for grid_options

qgrid/qgrid/grid.py

Lines 484 to 493 in 877b420

if grid_options is None:
grid_options = defaults.grid_options
else:
options = defaults.grid_options.copy()
options.update(grid_options)
grid_options = options
if not isinstance(grid_options, dict):
raise TypeError(
"grid_options must be dict, not %s" % type(grid_options)
)

@hickmanw hickmanw linked a pull request Oct 7, 2020 that will close this issue
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.

1 participant