diff --git a/lumen/filters/base.py b/lumen/filters/base.py index f11eaadc8..4969a6ae5 100644 --- a/lumen/filters/base.py +++ b/lumen/filters/base.py @@ -320,7 +320,7 @@ def __init__(self, **params): self.widget.link(self, bidirectional=True, value='value', visible='visible', disabled='disabled') if self._sync_with_url: pn.state.location.sync(self.widget, {'value': self.field}, on_error=self._url_sync_error) - if self.default is not None and not self.widget.value: + if self.default is not None and self.value is None: self.widget.value = self.default @classmethod diff --git a/lumen/tests/test_dashboard.py b/lumen/tests/test_dashboard.py index d1d5443cb..4c8159152 100644 --- a/lumen/tests/test_dashboard.py +++ b/lumen/tests/test_dashboard.py @@ -110,6 +110,18 @@ def test_dashboard_with_url_sync_filters_with_default(set_root, document): assert f2.value == ['foo1', 'foo2', 'foo3'] assert f2.widget.value == ['foo1', 'foo2', 'foo3'] +def test_dashboard_with_url_sync_filters_with_overwritten_default(set_root, document): + root = pathlib.Path(__file__).parent / 'sample_dashboard' + set_root(str(root)) + dashboard = Dashboard(str(root / 'sync_query_filters_default.yaml')) + dashboard._render_dashboard() + layout = dashboard.layouts[0] + f1, f2 = list(layout._pipelines.values())[0].filters + f1.value = (0.1, 0.7) + f2.value = [] # overwriting default with empty list + assert pn.state.location.search == '?A=%5B0.1%2C+0.7%5D&C=%5B%5D' + assert f2.widget.value == [] + @sql_available def test_dashboard_with_sql_source_and_transforms(set_root, document, mixed_df_object_type): root = pathlib.Path(__file__).parent / 'sample_dashboard'