diff --git a/packages/python/plotly/plotly/basedatatypes.py b/packages/python/plotly/plotly/basedatatypes.py index fe81e1874ec..bf5eac3dfab 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 key not 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 @@ -4778,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