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] Save data widget crash on no data #3311

Merged
merged 9 commits into from
Oct 25, 2018
Merged

[FIX] Save data widget crash on no data #3311

merged 9 commits into from
Oct 25, 2018

Conversation

golbog
Copy link
Contributor

@golbog golbog commented Oct 12, 2018

Issue

Fixes #3256.

Description of changes

Does not crash on empty data anymore.

Includes
  • Code changes
  • Tests
  • Documentation

@stuart-cls
Copy link

Thanks. Should there be a test added as well so this can't happen to other widgets?

Copy link
Contributor

@janezd janezd left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The fix introduces a different bug. See the comments.

The bug occurred because the conditions in the code are too complex to be manageable. I had a feeling that some cases are not covered but needed some time to decipher which. I think you should simplify the conditions.

Better still: is this change really needed? The new code is much longer and more complex than the original. What do we gain by the change?

if data is not None:
self.save_file()
if data is None:
return
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

self.data = data? Or, equivalently, self.data = None?

self.controls.filetype.insertItems(0, [item for item, _, supports_sparse in FILE_TYPES
if supports_sparse])
else:
if (self.data is None and data.is_sparse()) or (
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

These conditions do not cover the case self.data is None and not data.is_sparse().

Connect some sparse data to the widget. This will remove the formats that do not support sparse data. Then remove the signal to set self.data to None. Then connect some non-sparse data. After this, the widget will (incorrectly) show only formats for sparse data.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I can't seem to replicate this bug.
I've tested like you described here, but it shows correct formats.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Have you added self.data = data before line 132? This line is needed to ensure that self.data stores the current data and just not the last data seen by the widget. At the moment it may not matter, but it may introduce bugs in the future by defying expectations of what is in self.data.

I still don't understand the purpose of the change. However, even if there is/was no bug, the code is overly complicated and repetitive. I suppose the intention was to update the combo only when the sparsity of the new data is different from the previous. This translates to self.data is None or self.data.is_sparse() != data.is_sparse() (condition data is None is take care of earlier). This makes the code more readable and half shorter:

    if self.data is None or self.data.is_sparse() != data.is_sparse():
        self.controls.filetype.clear()
        allowed = [item for item, _, supports_sparse in FILE_TYPES
                   if supports_sparse or not data.is_sparse()]
        self.controls.filetype.insertItems(0, allowed)
        self.filetype = allowed[0]
        self.update_extension()

@janezd
Copy link
Contributor

janezd commented Oct 24, 2018

Could you squash the commits?

Revert "Fix for crash on empty data, better handling on sparcisity changes"

This reverts commit 246795b9bc2c343d4214cf42a986f2a6be40b732.

Fix for empty data crash, better handling of sparse data


Merge remote-tracking branch 'origin/owsave' into owsave
@codecov
Copy link

codecov bot commented Oct 25, 2018

Codecov Report

Merging #3311 into master will decrease coverage by 0.49%.
The diff coverage is 100%.

@@            Coverage Diff            @@
##           master    #3311     +/-   ##
=========================================
- Coverage   82.57%   82.07%   -0.5%     
=========================================
  Files         348      351      +3     
  Lines       61395    61922    +527     
=========================================
+ Hits        50697    50824    +127     
- Misses      10698    11098    +400

else:
self.controls.filetype.insertItems(0, [item for item, _, _ in FILE_TYPES])
items = [item for item, _, _ in FILE_TYPES]
if not items == [self.controls.filetype.itemText(i)
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

if items != ...

else:
self.controls.filetype.insertItems(0, [item for item, _, _ in FILE_TYPES])
items = [item for item, _, _ in FILE_TYPES]
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

OK, that's one way to do it. It may be a matter of opinion, but isn't

items = [item for item, _, supports_sparse in FILE_TYPES
         if supports_sparse or not data.is_sparse()]

more concise and shorter than if's with separate comprehensions? :)

@janezd janezd merged commit d002c46 into biolab:master Oct 25, 2018
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants