Skip to content

Commit 88c0745

Browse files
committed
colors: Do not crash on invalid colors
When colors are inferred from variable's attributes, something might go wrong (i.e. invalid value). Instead of crashing, default colors are now used.
1 parent 939438b commit 88c0745

File tree

2 files changed

+11
-2
lines changed

2 files changed

+11
-2
lines changed

Orange/data/variable.py

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -471,10 +471,11 @@ def number_of_decimals(self):
471471
@property
472472
def colors(self):
473473
if self._colors is None:
474-
if "colors" in self.attributes:
474+
try:
475475
col1, col2, black = self.attributes["colors"]
476476
self._colors = (hex_to_color(col1), hex_to_color(col2), black)
477-
else:
477+
except (KeyError, ValueError):
478+
# Stored colors were not available or invalid, use defaults
478479
self._colors = ((0, 0, 255), (255, 255, 0), False)
479480
return self._colors
480481

Orange/widgets/data/tests/test_owcolor.py

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,3 +19,11 @@ def test_reuse_old_settings(self):
1919

2020
w = self.create_widget(OWColor, reset_default_settings=False)
2121
self.send_signal("Data", self.iris, widget=w)
22+
23+
def test_invalid_input_colors(self):
24+
a = ContinuousVariable("a")
25+
a.attributes["colors"] = "invalid"
26+
a.colors
27+
t = Table(Domain([a]))
28+
29+
self.send_signal("Data", t)

0 commit comments

Comments
 (0)