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

BUG: Handle item is None in certain conditions #1649

Merged
merged 4 commits into from
Sep 19, 2022

Conversation

pllim
Copy link
Contributor

@pllim pllim commented Sep 13, 2022

Description

This pull request is to not let Imviz crash in certain use cases. I am not sure how to write unit test for this.

Fixes #689
Fixes #1614

Checklist for package maintainer(s)

This checklist is meant to remind the package maintainer(s) who will review this pull request of some common things to look for. This list is not exhaustive.

  • Are two approvals required? Branch protection rule does not check for the second approval. If a second approval is not necessary, please apply the trivial label.
  • Do the proposed changes actually accomplish desired goals? Also manually run the affected example notebooks, if necessary.
  • Do the proposed changes follow the STScI Style Guides?
  • Are tests added/updated as required? If so, do they follow the STScI Style Guides?
  • Are docs added/updated as required? If so, do they follow the STScI Style Guides?
  • Did the CI pass? If not, are the failures related?
  • Is a change log needed? If yes, is it added to CHANGES.rst?
  • Is a milestone set?
  • After merge, any internal documentations need updating (e.g., JIRA, Innerspace)?

@pllim pllim added bug Something isn't working imviz labels Sep 13, 2022
@pllim pllim added this to the 2.11 milestone Sep 13, 2022
@pllim pllim requested a review from camipacifici September 13, 2022 21:05
@codecov
Copy link

codecov bot commented Sep 13, 2022

Codecov Report

Base: 86.75% // Head: 86.76% // Increases project coverage by +0.01% 🎉

Coverage data is based on head (5be2035) compared to base (c3940e1).
Patch coverage: 100.00% of modified lines in pull request are covered.

Additional details and impacted files
@@            Coverage Diff             @@
##             main    #1649      +/-   ##
==========================================
+ Coverage   86.75%   86.76%   +0.01%     
==========================================
  Files          95       95              
  Lines        9639     9652      +13     
==========================================
+ Hits         8362     8375      +13     
  Misses       1277     1277              
Impacted Files Coverage Δ
jdaviz/configs/default/plugins/viewers.py 95.65% <100.00%> (+0.07%) ⬆️
jdaviz/configs/imviz/plugins/parsers.py 100.00% <100.00%> (ø)
jdaviz/core/helpers.py 67.88% <100.00%> (+1.21%) ⬆️

Help us with your feedback. Take ten seconds to tell us how you rate us. Have a feature suggestion? Share it here.

☔ View full report at Codecov.
📢 Do you have feedback about the report comment? Let us know in this issue.

Comment on lines +127 to +128
if viewer_item is None:
return
Copy link
Member

Choose a reason for hiding this comment

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

this gets triggered when the viewer is removed from the app before the layer update messages are processed? If so, I think this makes sense as a good way to quickly prevent that case from causing issues. We don't need to worry about any of the following logic (which only affects things in the viewer, not higher in the stack) since the viewer is no longer in the app.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

This one is for #1614 . I don't grok all the callback stuff but when this happens:

  114 viewer_item = self.jdaviz_app._viewer_item_by_id(self.reference_id)
 --> 115 selected_data_items = viewer_item['selected_data_items']

self.reference_id actually points to the deleted viewer ID (not sure why, maybe upstream bug). So I think returning here is good enough until we find a better fix.

jdaviz/app.py Outdated
Comment on lines 1303 to 1314
if data_item is None:
label = None
Copy link
Member

Choose a reason for hiding this comment

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

what scenario triggers this case? I'm just trying to think if there's a way we can prevent it entirely, or if not if the warning that it will raise is warranted or will be to noisy.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

For this one, I cannot reproduce it, so I just looked at the traceback at #689 (comment) and did my best guess.

Copy link
Member

Choose a reason for hiding this comment

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

ok, at least its not a common scenario then. I don't think the extra logic to prevent an error is a problem... as long as it doesn't result in a lot of warnings for the user. But I guess we'll at least have to reproduce (or find someone who can) before closing that issue. I'll try to do some testing before approving, but otherwise the code changes themselves look good to me! Thanks!

Copy link
Member

@kecnry kecnry left a comment

Choose a reason for hiding this comment

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

I was able to reproduce #689 on main. This PR does prevent the traceback, but I still don't think the workflow in #689 is handled correctly. My vote would be to merge this PR as-is but NOT close that issue (which I'll update with what I'm seeing and how to reproduce) with this PR.

(Regression test coverage would be nice, but I'm not sure if API calls to remove viewers would have the signals processed in the same order to reproduce the traceback or not... it might be worth a shot though!)

@pllim
Copy link
Contributor Author

pllim commented Sep 16, 2022

@kecnry , you mean regression test for #1614?

@kecnry
Copy link
Member

kecnry commented Sep 16, 2022

I suppose both really (coverage for the new lines of code to ensure they avoid those tracebacks)

@pllim pllim force-pushed the no-crashing-no-cry branch from 50f7dba to 1bd3d38 Compare September 16, 2022 21:43
@pllim

This comment was marked as outdated.

@pllim
Copy link
Contributor Author

pllim commented Sep 16, 2022

@kecnry , so I think only 2 remaining things:

  1. I need a workflow if you want me to add a test for Imviz: Unable to reload same file multiple times #689. I already added one for delete subset traceback after removing viewer #1614 here.
  2. I also added logic to handle Imviz: Unable to reload same file multiple times #689 (comment) . With this addition, would this PR now actually close that issue or you still want to keep it open?

@pllim pllim force-pushed the no-crashing-no-cry branch from 7bf7a68 to 54e6b3e Compare September 16, 2022 22:44
@kecnry
Copy link
Member

kecnry commented Sep 19, 2022

@pllim - is the workflow I added in #689 not sufficient for the test? It looks like your change to appropriately handle the index does fix the original problem - I wonder if the if data_item is None check should now be removed so that if any other bug uncovers a similar situation it won't silently be ignored and difficult to track down? Or do you think its better to leave that safeguard in to avoid tracebacks for the user?

@pllim
Copy link
Contributor Author

pllim commented Sep 19, 2022

if the if data_item is None check should now be removed

Hmm... If it is not needed for this fix, I guess we can remove it. Lemme see.

now creates a duplicate every time instead of overwriting the second one.
This is different from original 0th order fix for spacetelescope#600
which I confirmed that it fails without this patch.

Mark line to be excluded from bandit check.

Update result for affected remote test.
so the error will crop back up for other cases
@pllim pllim force-pushed the no-crashing-no-cry branch from 54e6b3e to 5be2035 Compare September 19, 2022 15:27
@pllim
Copy link
Contributor Author

pllim commented Sep 19, 2022

is the workflow I added in #689 not sufficient for the test?

I think there are 2 different problems being discussed at Issue 689.

Copy link
Collaborator

@rosteen rosteen left a comment

Choose a reason for hiding this comment

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

Looks good to me, I confirmed that both of the linked bugs are fixed by this. Thanks!

@pllim pllim merged commit 1639526 into spacetelescope:main Sep 19, 2022
@pllim pllim deleted the no-crashing-no-cry branch September 19, 2022 17:35
@pllim
Copy link
Contributor Author

pllim commented Sep 19, 2022

Thanks for the reviews!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging this pull request may close these issues.

delete subset traceback after removing viewer Imviz: Unable to reload same file multiple times
3 participants