Repository: biolab/orange3

Issue:
OWTSNE crashes when reopening workflow with selected data
##### Orange version
<!-- From menu _Help→About→Version_ or code `Orange.version.full_version` -->
master

##### Expected behavior
I can open a workflow properly.


##### Actual behavior

```
Traceback (most recent call last):
  File "/home/pavlin/dev/orange3/Orange/canvas/scheme/widgetsscheme.py", line 1083, in process_signals_for_widget
    widget.handleNewSignals()
  File "/home/pavlin/dev/orange3/Orange/widgets/visualize/utils/widget.py", line 453, in handleNewSignals
    self.commit()
  File "/home/pavlin/dev/orange3/Orange/widgets/gui.py", line 2042, in unconditional_commit
    do_commit()
  File "/home/pavlin/dev/orange3/Orange/widgets/gui.py", line 2050, in do_commit
    commit()
  File "/home/pavlin/dev/orange3/Orange/widgets/unsupervised/owtsne.py", line 253, in commit
    super().commit()
  File "/home/pavlin/dev/orange3/Orange/widgets/visualize/utils/widget.py", line 511, in commit
    self.send_data()
  File "/home/pavlin/dev/orange3/Orange/widgets/visualize/utils/widget.py", line 516, in send_data
    group_sel = np.zeros(len(data), dtype=int)
TypeError: object of type 'NoneType' has no len()

```


##### Steps to reproduce the behavior
1. Connect File to t-SNE and select some data. Save the workflow
2. Reopen the workflow → t-sNE crash


##### Additional info (worksheets, data, screenshots, ...)





Discussion:

Resolving patch:
diff --git a/Orange/widgets/unsupervised/owtsne.py b/Orange/widgets/unsupervised/owtsne.py
--- a/Orange/widgets/unsupervised/owtsne.py
+++ b/Orange/widgets/unsupervised/owtsne.py
@@ -254,12 +254,16 @@ def commit(self):
         self.send_preprocessor()
 
     def _get_projection_data(self):
-        if self.data is None or self.projection is None:
+        if self.data is None:
             return None
+        if self.projection is None:
+            variables = self._get_projection_variables()
+        else:
+            variables = self.projection.domain.attributes
         data = self.data.transform(
             Domain(self.data.domain.attributes,
                    self.data.domain.class_vars,
-                   self.data.domain.metas + self.projection.domain.attributes))
+                   self.data.domain.metas + variables))
         data.metas[:, -2:] = self.get_embedding()
         return data
 


Test patch:
diff --git a/Orange/widgets/tests/base.py b/Orange/widgets/tests/base.py
--- a/Orange/widgets/tests/base.py
+++ b/Orange/widgets/tests/base.py
@@ -960,6 +960,15 @@ def test_invalidated_embedding(self, timeout=DEFAULT_TIMEOUT):
         self.widget.graph.update_coordinates.assert_not_called()
         self.widget.graph.update_point_props.assert_called_once()
 
+    def test_saved_selection(self):
+        self.send_signal(self.widget.Inputs.data, self.data)
+        self.widget.graph.select_by_indices(list(range(0, len(self.data), 10)))
+        settings = self.widget.settingsHandler.pack_data(self.widget)
+        w = self.create_widget(self.widget.__class__, stored_settings=settings)
+        self.send_signal(self.widget.Inputs.data, self.data, widget=w)
+        self.assertEqual(np.sum(w.graph.selection), 15)
+        np.testing.assert_equal(self.widget.graph.selection, w.graph.selection)
+
     def test_send_report(self, timeout=DEFAULT_TIMEOUT):
         """Test report """
         self.send_signal(self.widget.Inputs.data, self.data)