Skip to content

Commit 908594c

Browse files
committed
migrate_context: widgets crashed when migrating context without version
1 parent 5fd880c commit 908594c

File tree

8 files changed

+83
-31
lines changed

8 files changed

+83
-31
lines changed

Orange/widgets/tests/base.py

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -839,6 +839,13 @@ def _compare_selected_annotated_domains(self, selected, annotated):
839839
annotated_vars = annotated.domain.variables + annotated.domain.metas
840840
self.assertLess(set(selected_vars), set(annotated_vars))
841841

842+
def test_migrate_context_without_version(self):
843+
self.send_signal(self.signal_name, self.signal_data)
844+
settings = self.widget.settingsHandler.pack_data(self.widget)
845+
if "context_settings" in settings:
846+
del settings["context_settings"][0].values["__version__"]
847+
self.create_widget(self.widget.__class__, stored_settings=settings)
848+
842849

843850
class ProjectionWidgetTestMixin:
844851
"""Class for projection widget testing"""
@@ -1017,6 +1024,12 @@ def test_send_report(self, timeout=DEFAULT_TIMEOUT):
10171024
self.send_signal(self.widget.Inputs.data, None)
10181025
self.widget.report_button.click()
10191026

1027+
def test_migrate_context_without_version(self):
1028+
self.send_signal(self.signal_name, self.signal_data)
1029+
settings = self.widget.settingsHandler.pack_data(self.widget)
1030+
del settings["context_settings"][0].values["__version__"]
1031+
self.create_widget(self.widget.__class__, stored_settings=settings)
1032+
10201033

10211034
class AnchorProjectionWidgetTestMixin(ProjectionWidgetTestMixin):
10221035
def test_embedding_missing_values(self):

Orange/widgets/unsupervised/owmds.py

Lines changed: 12 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -549,7 +549,7 @@ def migrate_settings(cls, settings_, version):
549549

550550
@classmethod
551551
def migrate_context(cls, context, version):
552-
if version < 2:
552+
if version < 2 and hasattr(context, "ordered_domain"):
553553
domain = context.ordered_domain
554554
n_domain = [t for t in context.ordered_domain if t[1] == 2]
555555
c_domain = [t for t in context.ordered_domain if t[1] == 1]
@@ -567,12 +567,18 @@ def migrate_context(cls, context, version):
567567
context_values[new_val] = tmp
568568
context.values = context_values
569569

570-
if version < 3 and "graph" in context.values:
570+
if version < 3:
571571
values = context.values
572-
values["attr_color"] = values["graph"]["attr_color"]
573-
values["attr_size"] = values["graph"]["attr_size"]
574-
values["attr_shape"] = values["graph"]["attr_shape"]
575-
values["attr_label"] = values["graph"]["attr_label"]
572+
if "graph" in values:
573+
graph = values["graph"]
574+
if "attr_color" in graph:
575+
values["attr_color"] = graph["attr_color"]
576+
if "attr_size" in graph:
577+
values["attr_size"] = graph["attr_size"]
578+
if "attr_shape" in graph:
579+
values["attr_shape"] = graph["attr_shape"]
580+
if "attr_label" in graph:
581+
values["attr_label"] = graph["attr_label"]
576582

577583

578584
if __name__ == "__main__": # pragma: no cover

Orange/widgets/unsupervised/owtsne.py

Lines changed: 10 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -412,10 +412,16 @@ def migrate_settings(cls, settings, version):
412412
def migrate_context(cls, context, version):
413413
if version < 3:
414414
values = context.values
415-
values["attr_color"] = values["graph"]["attr_color"]
416-
values["attr_size"] = values["graph"]["attr_size"]
417-
values["attr_shape"] = values["graph"]["attr_shape"]
418-
values["attr_label"] = values["graph"]["attr_label"]
415+
if "graph" in values:
416+
graph = values["graph"]
417+
if "attr_color" in graph:
418+
values["attr_color"] = graph["attr_color"]
419+
if "attr_size" in graph:
420+
values["attr_size"] = graph["attr_size"]
421+
if "attr_shape" in graph:
422+
values["attr_shape"] = graph["attr_shape"]
423+
if "attr_label" in graph:
424+
values["attr_label"] = graph["attr_label"]
419425

420426

421427
if __name__ == "__main__":

Orange/widgets/visualize/owfreeviz.py

Lines changed: 10 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -391,10 +391,16 @@ def migrate_settings(cls, _settings, version):
391391
def migrate_context(cls, context, version):
392392
if version < 3:
393393
values = context.values
394-
values["attr_color"] = values["graph"]["attr_color"]
395-
values["attr_size"] = values["graph"]["attr_size"]
396-
values["attr_shape"] = values["graph"]["attr_shape"]
397-
values["attr_label"] = values["graph"]["attr_label"]
394+
if "graph" in values:
395+
graph = values["graph"]
396+
if "attr_color" in graph:
397+
values["attr_color"] = graph["attr_color"]
398+
if "attr_size" in graph:
399+
values["attr_size"] = graph["attr_size"]
400+
if "attr_shape" in graph:
401+
values["attr_shape"] = graph["attr_shape"]
402+
if "attr_label" in graph:
403+
values["attr_label"] = graph["attr_label"]
398404

399405

400406
class MoveIndicator(pg.GraphicsObject):

Orange/widgets/visualize/owlinearprojection.py

Lines changed: 12 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -493,7 +493,7 @@ def migrate_settings(cls, settings_, version):
493493

494494
@classmethod
495495
def migrate_context(cls, context, version):
496-
if version < 2:
496+
if version < 2 and hasattr(context, "ordered_domain"):
497497
domain = context.ordered_domain
498498
c_domain = [t for t in context.ordered_domain if t[1] == 2]
499499
d_domain = [t for t in context.ordered_domain if t[1] == 1]
@@ -509,12 +509,18 @@ def migrate_context(cls, context, version):
509509
"attr_shape": context.values["attr_shape"],
510510
"attr_size": context.values["attr_size"]
511511
}
512-
if version == 3:
512+
if version < 4:
513513
values = context.values
514-
values["attr_color"] = values["graph"]["attr_color"]
515-
values["attr_size"] = values["graph"]["attr_size"]
516-
values["attr_shape"] = values["graph"]["attr_shape"]
517-
values["attr_label"] = values["graph"]["attr_label"]
514+
if "graph" in values:
515+
graph = values["graph"]
516+
if "attr_color" in graph:
517+
values["attr_color"] = graph["attr_color"]
518+
if "attr_size" in graph:
519+
values["attr_size"] = graph["attr_size"]
520+
if "attr_shape" in graph:
521+
values["attr_shape"] = graph["attr_shape"]
522+
if "attr_label" in graph:
523+
values["attr_label"] = graph["attr_label"]
518524

519525

520526
def column_data(table, var, dtype):

Orange/widgets/visualize/owradviz.py

Lines changed: 10 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -405,10 +405,16 @@ def clear(self):
405405
def migrate_context(cls, context, version):
406406
if version < 2:
407407
values = context.values
408-
values["attr_color"] = values["graph"]["attr_color"]
409-
values["attr_size"] = values["graph"]["attr_size"]
410-
values["attr_shape"] = values["graph"]["attr_shape"]
411-
values["attr_label"] = values["graph"]["attr_label"]
408+
if "graph" in values:
409+
graph = values["graph"]
410+
if "attr_color" in graph:
411+
values["attr_color"] = graph["attr_color"]
412+
if "attr_size" in graph:
413+
values["attr_size"] = graph["attr_size"]
414+
if "attr_shape" in graph:
415+
values["attr_shape"] = graph["attr_shape"]
416+
if "attr_label" in graph:
417+
values["attr_label"] = graph["attr_label"]
412418

413419

414420
class MoveIndicator(pg.GraphicsObject):

Orange/widgets/visualize/owscatterplot.py

Lines changed: 12 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -502,12 +502,19 @@ def migrate_settings(cls, settings, version):
502502
def migrate_context(cls, context, version):
503503
values = context.values
504504
if version < 3:
505-
values["attr_color"] = values["graph"]["attr_color"]
506-
values["attr_size"] = values["graph"]["attr_size"]
507-
values["attr_shape"] = values["graph"]["attr_shape"]
508-
values["attr_label"] = values["graph"]["attr_label"]
505+
if "graph" in values:
506+
graph = values["graph"]
507+
if "attr_color" in graph:
508+
values["attr_color"] = graph["attr_color"]
509+
if "attr_size" in graph:
510+
values["attr_size"] = graph["attr_size"]
511+
if "attr_shape" in graph:
512+
values["attr_shape"] = graph["attr_shape"]
513+
if "attr_label" in graph:
514+
values["attr_label"] = graph["attr_label"]
509515
if version < 4:
510-
if values["attr_x"][1] % 100 == 1 or values["attr_y"][1] % 100 == 1:
516+
if "attr_x" in values and values["attr_x"][1] % 100 == 1 or \
517+
"attr_y" in values and values["attr_y"][1] % 100 == 1:
511518
raise IncompatibleContext()
512519

513520

Orange/widgets/visualize/owsieve.py

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -142,8 +142,10 @@ def showEvent(self, event):
142142
@classmethod
143143
def migrate_context(cls, context, version):
144144
if not version:
145-
settings.rename_setting(context, "attrX", "attr_x")
146-
settings.rename_setting(context, "attrY", "attr_y")
145+
if "attrX" in context.values:
146+
settings.rename_setting(context, "attrX", "attr_x")
147+
if "attrY" in context.values:
148+
settings.rename_setting(context, "attrY", "attr_y")
147149
settings.migrate_str_to_variable(context)
148150

149151
@Inputs.data

0 commit comments

Comments
 (0)