Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix TypeError: unhashable type: 'Template' during Figure construction #2447

Merged
merged 1 commit into from
May 7, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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](http://semver.org/).
### Fixed

- Fix `AttributeError: module 'plotly.graph_objs' has no attribute 'FigureWidget'` exception on `from plotly.graph_objs import *` when `ipywidgets` is not installed. Error also occurred when importing `plotly.figure_factor`. It is now possible to import `plotly.graph_objs.FigureWidget` when `ipywidgets` is not installed, and an informative `ImportError` exception will be raised in the `FigureWidget` constructor ([#2443](https://github.com/plotly/plotly.py/issues/2443), [#1111](https://github.com/plotly/plotly.py/issues/1111)).
- Fix `TypeError: unhashable type: 'Template'` during `Figure` construction when `plotly.io.templates.default` is set to a `Template` object rather than a string.


## [4.7.0] - 2020-05-06
Expand Down
10 changes: 8 additions & 2 deletions packages/python/plotly/plotly/basedatatypes.py
Original file line number Diff line number Diff line change
Expand Up @@ -1951,8 +1951,14 @@ def _initialize_layout_template(self):
if self._allow_disable_validation:
self._layout_obj._validate = False
try:
template_dict = pio.templates[pio.templates.default]
self._layout_obj.template = template_dict
if isinstance(pio.templates.default, BasePlotlyType):
# Template object. Don't want to actually import `Template`
# here for performance so we check against `BasePlotlyType`
template_object = pio.templates.default
else:
# Name of registered template object
template_object = pio.templates[pio.templates.default]
self._layout_obj.template = template_object
finally:
self._layout_obj._validate = self._validate

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -175,6 +175,12 @@ def test_template_in(self):
def test_template_iter(self):
self.assertIn("test_template", set(pio.templates))

def test_template_default_as_object(self):
template = go.layout.Template({"layout": {"font": {"family": "Rockwell"}}})
pio.templates.default = template
fig = go.Figure()
self.assertEqual(fig.layout.template, template)


class TestToTemplated(TestCaseNoTemplate):
def test_move_layout_nested_properties(self):
Expand Down