Skip to content

Commit

Permalink
Merge pull request #3011 from CNFeffery/dev
Browse files Browse the repository at this point in the history
Fix #3010 Assigning None to exact or shape array properties causes exception
  • Loading branch information
T4rk1n authored Sep 20, 2024
2 parents 0ff8e4e + d5b70b0 commit ef00323
Show file tree
Hide file tree
Showing 5 changed files with 66 additions and 2 deletions.
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
import React from 'react';
import PropTypes from 'prop-types';

const ArrayOfExactOrShapeWithNodePropAssignNone = (props) => {
const { id, test_array_of_exact_prop, test_array_of_shape_prop } = props;

return (
<div id={id}>
{`length of test_array_of_exact_prop: ${(test_array_of_exact_prop || []).length}, length of test_array_of_shape_prop: ${(test_array_of_shape_prop || []).length}`}
</div>
);
};

ArrayOfExactOrShapeWithNodePropAssignNone.propTypes = {
id: PropTypes.string,
test_array_of_exact_prop: PropTypes.arrayOf(
PropTypes.exact({
label: PropTypes.node,
value: PropTypes.string
})
),
test_array_of_shape_prop: PropTypes.arrayOf(
PropTypes.shape({
label: PropTypes.node,
value: PropTypes.string
})
)
};

export default ArrayOfExactOrShapeWithNodePropAssignNone;
4 changes: 3 additions & 1 deletion @plotly/dash-test-components/src/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ import DrawCounter from './components/DrawCounter';
import AddPropsComponent from "./components/AddPropsComponent";
import ReceivePropsComponent from "./components/ReceivePropsComponent";
import ShapeOrExactKeepOrderComponent from "./components/ShapeOrExactKeepOrderComponent";
import ArrayOfExactOrShapeWithNodePropAssignNone from './components/ArrayOfExactOrShapeWithNodePropAssignNone';


export {
Expand All @@ -27,5 +28,6 @@ export {
DrawCounter,
AddPropsComponent,
ReceivePropsComponent,
ShapeOrExactKeepOrderComponent
ShapeOrExactKeepOrderComponent,
ArrayOfExactOrShapeWithNodePropAssignNone
};
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ This project adheres to [Semantic Versioning](https://semver.org/).
## Fixed

- [#2994](https://github.com/plotly/dash/pull/2994) Keep generated doc-string order for shape or exact props. Fixes [#2990](https://github.com/plotly/dash/issues/2990)
- [#3011](https://github.com/plotly/dash/pull/3011) Fixed an exception error caused by assigning `None` to array properties with `exact` or `shape` element types. Fixes [#3010](https://github.com/plotly/dash/issues/3010)

## [2.18.1] - 2024-09-12

Expand Down
2 changes: 1 addition & 1 deletion dash/dash-renderer/src/TreeContainer.js
Original file line number Diff line number Diff line change
Expand Up @@ -322,7 +322,7 @@ class BaseTreeContainer extends Component {
});

node = rpath(frontPath, props);
if (node === undefined || !node.length) {
if (node === undefined || !node?.length) {
continue;
}
const firstNode = rpath(backPath, node[0]);
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
from dash import Dash, html

from dash_test_components import ArrayOfExactOrShapeWithNodePropAssignNone


def test_aoeoswnpsn001_array_of_exact_or_shape_with_node_prop_assign_none(dash_duo):
app = Dash(__name__)
app.layout = html.Div(
[
ArrayOfExactOrShapeWithNodePropAssignNone(
id="test-component1",
test_array_of_exact_prop=[{"label": c, "value": c} for c in "abc"],
test_array_of_shape_prop=[{"label": c, "value": c} for c in "abc"],
),
ArrayOfExactOrShapeWithNodePropAssignNone(
id="test-component2",
test_array_of_exact_prop=None,
test_array_of_shape_prop=None,
),
]
)

dash_duo.start_server(app)
dash_duo.wait_for_text_to_equal(
"#test-component1",
"length of test_array_of_exact_prop: 3, length of test_array_of_shape_prop: 3",
)
dash_duo.wait_for_text_to_equal(
"#test-component2",
"length of test_array_of_exact_prop: 0, length of test_array_of_shape_prop: 0",
)

0 comments on commit ef00323

Please sign in to comment.