Fix IndexError at startup when all view plugins are hidden#2360
Open
eduralph wants to merge 1 commit into
Open
Conversation
Hiding every view plugin in the Plugin Manager left Gramps with no available views, and on the next start the main window crashed with "IndexError: list assignment index out of range" before it could open. With no views to show, the view-selection logic used to report category 0 as the page to open even though no category existed, so startup tried to navigate into an empty view set and failed. It now reports "no category" when there are no views, and the interface simply opens with no active page. Opening the configuration dialog or loading a family tree in that same no-view state could hit the same crash from other directions; those paths now also resolve cleanly to "nothing to show" instead of raising. This complements the earlier per-case guards from commit d5d86e9 by making the empty-view set total at its source. Fixes #8796
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Fix IndexError at startup when all view plugins are hidden (#8796)
Root cause
When every view plugin is hidden in the Plugin Manager,
ViewManager.get_available_views()returns[], andviews_to_show([])collapsed to
(0, 0, [])— claiming category 0 exists when it does not. Atstartup
init_interfacethen calledgoto_page(0, 0), whoseself.current_views[cat_num] = view_numindexed the emptycurrent_viewslist and raised
IndexError: list assignment index out of range, crashingGramps before the window opened (#8796).
Fix
views_to_showis made total over the empty view set: with no views it nowreturns
(None, None, [])("no category to select") instead of(0, 0, []), andinit_interfaceonly navigates when a category exists, sothe app opens with no active page rather than crashing. The function is moved
into a new GTK-independent module
viewmanagerutils.pyso production and theregression test exercise the same implementation. Two sibling entry points
that reach the same empty-view state independently of startup navigation are
guarded the same way:
__change_page(reached via_post_load_newdb_guiwhen a tree auto-loads with zero views) and
config_view(the ConfigViewkeyboard action) now return early when there is no page / no active page.
Verified against
gramps/gui/viewmanagerutils.py:39-47— new gi-freeviews_to_showreturns
None, None, default_cat_viewswhenviewsis empty (targetbranch
maintenance/gramps61).gramps/gui/viewmanager.py:80—viewmanagerre-importsviews_to_showfrom
viewmanagerutils, so the production startup path routes through theexact function the test drives (no parallel copy).
gramps/gui/viewmanager.py:638-656—init_interfaceunpacks the tupleand navigates only
if current_cat is not None, leaving no active page onthe empty set.
gramps/gui/viewmanager.py:1051-1061—__change_pagereturns early whenself.pagesis empty (get_current_page()returns -1 on an emptynotebook, so
self.pages[-1]/self.pages[0]would raise).gramps/gui/viewmanager.py:1515-1524—config_viewreturns early whenself.active_page is None, so the ConfigView action does not dereferenceNone.Test
gramps/gui/test/viewmanager_test.py(new) drives the productionviews_to_showheadlessly and assertsviews_to_show([], use_last=False)and
views_to_show([], use_last=True)both return(None, None, [])— thecorrected, totality-restoring contract that prevents the startup
IndexError.Manual GUI repro on
maintenance/gramps61: hide every "Loaded Plugins" viewentry (or list all view plugins under
[plugin] hiddenpluginsingramps.ini) and restart — pre-fix Gramps crashes with theIndexError;post-fix it opens with no active page and no exception.