From f5846c73533feed53c226b4ab62536622bf2937c Mon Sep 17 00:00:00 2001 From: bbm Date: Tue, 14 Mar 2023 11:01:03 -0400 Subject: [PATCH 1/4] check for keys to be added to plotly_obj before calculating error message --- .../python/plotly/plotly/basedatatypes.py | 19 +++++++++---------- 1 file changed, 9 insertions(+), 10 deletions(-) diff --git a/packages/python/plotly/plotly/basedatatypes.py b/packages/python/plotly/plotly/basedatatypes.py index fe81e1874ec..1025e0ff5aa 100644 --- a/packages/python/plotly/plotly/basedatatypes.py +++ b/packages/python/plotly/plotly/basedatatypes.py @@ -3862,18 +3862,17 @@ def _perform_update(plotly_obj, update_obj, overwrite=False): # This should be valid even if xaxis2 hasn't been initialized: # >>> layout.update(xaxis2={'title': 'xaxis 2'}) for key in update_obj: + # special handling for missing keys that match _subplot_re_match + if not key in plotly_obj and isinstance(plotly_obj, BaseLayoutType): + # try _subplot_re_match + match = plotly_obj._subplot_re_match(key) + if match: + # We need to create a subplotid object + plotly_obj[key] = {} + continue + err = _check_path_in_prop_tree(plotly_obj, key, error_cast=ValueError) if err is not None: - if isinstance(plotly_obj, BaseLayoutType): - # try _subplot_re_match - match = plotly_obj._subplot_re_match(key) - if match: - # We need to create a subplotid object - plotly_obj[key] = {} - continue - # If no match, raise the error, which should already - # contain the _raise_on_invalid_property_error - # generated message raise err # Convert update_obj to dict From 6d5e1d782ae418bfcb1c5da448bad10942f25188 Mon Sep 17 00:00:00 2001 From: bbm Date: Tue, 14 Mar 2023 11:05:00 -0400 Subject: [PATCH 2/4] 'obj' was sometimes not None, but still did not have _valid_props attribute See plotly.tests.test_core.test_errors.test_dict_path_errors.test_described_subscript_error_on_type_error for an example --- packages/python/plotly/plotly/basedatatypes.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/packages/python/plotly/plotly/basedatatypes.py b/packages/python/plotly/plotly/basedatatypes.py index 1025e0ff5aa..7a9ebc91344 100644 --- a/packages/python/plotly/plotly/basedatatypes.py +++ b/packages/python/plotly/plotly/basedatatypes.py @@ -4777,7 +4777,7 @@ def __contains__(self, prop): else: return False else: - if obj is not None and p in obj._valid_props: + if hasattr(obj, '_valid_props') and p in obj._valid_props: obj = obj[p] else: return False From c795b3b8ab519b1af24b6ed98ebdca59378dd4c6 Mon Sep 17 00:00:00 2001 From: bbm Date: Tue, 14 Mar 2023 11:24:28 -0400 Subject: [PATCH 3/4] use double-quotes as suggested by black --- packages/python/plotly/plotly/basedatatypes.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/packages/python/plotly/plotly/basedatatypes.py b/packages/python/plotly/plotly/basedatatypes.py index 7a9ebc91344..b9db5666a37 100644 --- a/packages/python/plotly/plotly/basedatatypes.py +++ b/packages/python/plotly/plotly/basedatatypes.py @@ -4777,7 +4777,7 @@ def __contains__(self, prop): else: return False else: - if hasattr(obj, '_valid_props') and p in obj._valid_props: + if hasattr(obj, "_valid_props") and p in obj._valid_props: obj = obj[p] else: return False From c82aad7591d4ef6058e2bcb22dac40a4d4524d46 Mon Sep 17 00:00:00 2001 From: Alex Johnson Date: Thu, 16 Mar 2023 17:38:58 -0400 Subject: [PATCH 4/4] Update packages/python/plotly/plotly/basedatatypes.py --- packages/python/plotly/plotly/basedatatypes.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/packages/python/plotly/plotly/basedatatypes.py b/packages/python/plotly/plotly/basedatatypes.py index b9db5666a37..bf5eac3dfab 100644 --- a/packages/python/plotly/plotly/basedatatypes.py +++ b/packages/python/plotly/plotly/basedatatypes.py @@ -3863,7 +3863,7 @@ def _perform_update(plotly_obj, update_obj, overwrite=False): # >>> layout.update(xaxis2={'title': 'xaxis 2'}) for key in update_obj: # special handling for missing keys that match _subplot_re_match - if not key in plotly_obj and isinstance(plotly_obj, BaseLayoutType): + if key not in plotly_obj and isinstance(plotly_obj, BaseLayoutType): # try _subplot_re_match match = plotly_obj._subplot_re_match(key) if match: