Skip to content

Commit 9ec6d60

Browse files
committed
Merge branch 'dev' into cleaned-pmc
2 parents 5035be2 + 8d59373 commit 9ec6d60

File tree

9 files changed

+64
-16
lines changed

9 files changed

+64
-16
lines changed

CHANGELOG.md

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@ This project adheres to [Semantic Versioning](https://semver.org/).
55
## [Unreleased]
66

77
### Changed
8+
- [#1876](https://github.com/plotly/dash/pull/1876) Delays finalizing `Dash.config` attributes not used in the constructor until `init_app()`.
89
- [#1869](https://github.com/plotly/dash/pull/1869), [#1873](https://github.com/plotly/dash/pull/1873) Upgrade Plotly.js to v2.8.3. This includes:
910
- [Feature release 2.5.0](https://github.com/plotly/plotly.js/releases/tag/v2.5.0):
1011
- 3D traces are now compatible with `no-unsafe-eval` CSP rules.
@@ -29,6 +30,9 @@ This project adheres to [Semantic Versioning](https://semver.org/).
2930
- `dash[ci]`: mainly for internal use, these are additional requirements for the Dash CI tests, exposed for other component libraries to use a matching configuration.
3031

3132
### Added
33+
- [#1883](https://github.com/plotly/dash/pull/1883) in DataTable added `page_current` to `persisted_props` as requested in [#1860](https://github.com/plotly/dash/issues/1860)
34+
35+
3236

3337
- [#1763](https://github.com/plotly/dash/pull/1763):
3438
## Dash and Dash Renderer
@@ -183,6 +187,9 @@ This project adheres to [Semantic Versioning](https://semver.org/).
183187
- [#1779](https://github.com/plotly/dash/pull/1779):
184188
- Clean up our handling of serialization problems, including fixing `orjson` for Python 3.6
185189
- Added the ability for `dash.testing` `percy_snapshot` methods to choose widths to generate.
190+
191+
- [#1778](https://github.com/plotly/dash/pull/1778) DataTable: Fix React warnings stating
192+
that each child in a list should have a unique "key" prop
186193

187194
## [2.0.0] - 2021-08-03
188195

components/dash-core-components/CHANGELOG.md

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,6 @@
11
# Change Log for dash-core-components
2+
### NOTE: as of v2.0, changes in dash-core-component are all being recorded in the main dash changelog.
3+
### This file is kept only for historical purposes.
24
All notable changes to this project will be documented in this file.
35
This project adheres to [Semantic Versioning](http://semver.org/).
46

components/dash-html-components/CHANGELOG.md

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,6 @@
11
# Change Log for dash-html-components
2+
### NOTE: as of v2.0, changes in dash-html-components are all being recorded in the main dash changelog.
3+
### This file is kept only for historical purposes.
24
All notable changes to this project will be documented in this file.
35
This project adheres to [Semantic Versioning](http://semver.org/).
46

components/dash-table/CHANGELOG.md

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,9 @@
11
# Change Log for dash-table
2+
### NOTE: as of v2.0, changes in dash-table are all being recorded in the main dash changelog.
3+
### This file is kept only for historical purposes.
24
All notable changes to this project will be documented in this file.
35
This project adheres to [Semantic Versioning](http://semver.org/).
46

5-
## [Unreleased]
6-
### Fixed
7-
- [#1778](https://github.com/plotly/dash/pull/1778) Fix React warnings stating
8-
that each child in a list should have a unique "key" prop
97

108
## [4.12.0] - 2021-07-09
119
### Fixed

components/dash-table/src/dash-table/dash/DataTable.js

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -101,6 +101,7 @@ export const defaultProps = {
101101
'columns.name',
102102
'filter_query',
103103
'hidden_columns',
104+
'page_current',
104105
'selected_columns',
105106
'selected_rows',
106107
'sort_by'
@@ -1537,6 +1538,7 @@ export const propTypes = {
15371538
'data',
15381539
'filter_query',
15391540
'hidden_columns',
1541+
'page_current',
15401542
'selected_columns',
15411543
'selected_rows',
15421544
'sort_by'

dash/_utils.py

Lines changed: 18 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -137,23 +137,37 @@ def __getattr__(self, key):
137137
raise AttributeError(key)
138138

139139
def set_read_only(self, names, msg="Attribute is read-only"):
140-
object.__setattr__(self, "_read_only", names)
141-
object.__setattr__(self, "_read_only_msg", msg)
140+
"""
141+
Designate named attributes as read-only with the corresponding msg
142+
143+
Method is additive. Making additional calls to this method will update
144+
existing messages and add to the current set of _read_only names.
145+
"""
146+
new_read_only = {name: msg for name in names}
147+
if getattr(self, "_read_only", False):
148+
self._read_only.update(new_read_only)
149+
else:
150+
object.__setattr__(self, "_read_only", new_read_only)
142151

143152
def finalize(self, msg="Object is final: No new keys may be added."):
144153
"""Prevent any new keys being set."""
145154
object.__setattr__(self, "_final", msg)
146155

147156
def __setitem__(self, key, val):
148-
if key in self.__dict__.get("_read_only", []):
149-
raise AttributeError(self._read_only_msg, key)
157+
if key in self.__dict__.get("_read_only", {}):
158+
raise AttributeError(self._read_only[key], key)
150159

151160
final_msg = self.__dict__.get("_final")
152161
if final_msg and key not in self:
153162
raise AttributeError(final_msg, key)
154163

155164
return super().__setitem__(key, val)
156165

166+
def update(self, other):
167+
# Overrides dict.update() to use __setitem__ above
168+
for k, v in other.items():
169+
self[k] = v
170+
157171
# pylint: disable=inconsistent-return-statements
158172
def first(self, *names):
159173
for name in names:

dash/dash.py

Lines changed: 12 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -356,9 +356,6 @@ def __init__(
356356
"assets_folder",
357357
"assets_url_path",
358358
"eager_loading",
359-
"url_base_pathname",
360-
"routes_pathname_prefix",
361-
"requests_pathname_prefix",
362359
"serve_locally",
363360
"compress",
364361
],
@@ -427,8 +424,19 @@ def __init__(
427424

428425
self.logger.setLevel(logging.INFO)
429426

430-
def init_app(self, app=None):
427+
def init_app(self, app=None, **kwargs):
431428
"""Initialize the parts of Dash that require a flask app."""
429+
430+
self.config.update(kwargs)
431+
self.config.set_read_only(
432+
[
433+
"url_base_pathname",
434+
"routes_pathname_prefix",
435+
"requests_pathname_prefix",
436+
],
437+
"Read-only: can only be set in the Dash constructor or during init_app()",
438+
)
439+
432440
config = self.config
433441

434442
if app is not None:

tests/unit/dash/test_utils.py

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -24,12 +24,13 @@ def test_ddut001_attribute_dict():
2424
assert a.k == 2
2525
assert a["k"] == 2
2626

27-
a.set_read_only(["k", "q"], "boo")
27+
a.set_read_only(["k"], "boo")
2828

2929
with pytest.raises(AttributeError) as err:
3030
a.k = 3
3131
assert err.value.args == ("boo", "k")
3232
assert a.k == 2
33+
assert a._read_only == {"k": "boo"}
3334

3435
with pytest.raises(AttributeError) as err:
3536
a["k"] = 3
@@ -38,13 +39,11 @@ def test_ddut001_attribute_dict():
3839

3940
a.set_read_only(["q"])
4041

41-
a.k = 3
42-
assert a.k == 3
43-
4442
with pytest.raises(AttributeError) as err:
4543
a.q = 3
4644
assert err.value.args == ("Attribute is read-only", "q")
4745
assert "q" not in a
46+
assert a._read_only == {"k": "boo", "q": "Attribute is read-only"}
4847

4948
a.finalize("nope")
5049

tests/unit/test_configs.py

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -370,3 +370,19 @@ def test_title():
370370
assert "<title>Hello World</title>" in app.index()
371371
app = Dash(title="Custom Title")
372372
assert "<title>Custom Title</title>" in app.index()
373+
374+
375+
def test_app_delayed_config():
376+
app = Dash(server=False)
377+
app.init_app(app=Flask("test"), requests_pathname_prefix="/dash/")
378+
379+
assert app.config.requests_pathname_prefix == "/dash/"
380+
381+
with pytest.raises(AttributeError):
382+
app.config.name = "cannot update me"
383+
384+
385+
def test_app_invalid_delayed_config():
386+
app = Dash(server=False)
387+
with pytest.raises(AttributeError):
388+
app.init_app(app=Flask("test"), name="too late 2 update")

0 commit comments

Comments
 (0)