Repository navigation
Conversation
In `python/grass/pygrass/raster/abstract.py`, `RasterAbstractBase.set_region()` and `set_region_from_rast()` previously called `fatal()` and a bare `raise` when invoked on an open raster map, causing a process exit via `sys.exit()` or a `RuntimeError` due to missing active exception context. Additionally, `RasterAbstractBase.__getitem__()` called `fatal()` when passed an invalid key type instead of raising `TypeError`. Fix this by: - Raising `GrassError` when region modifications are attempted on an open raster map. - Raising `TypeError` on unsupported index key types in `__getitem__()`. - Removing the unused `fatal` import. - Adding unit tests in `test_pygrass_raster.py`. Fixes OSGeo#7993. Signed-off-by: bhuvan-somisetty <somisettybhuvan5@gmail.com>
bhuvan-somisetty
force-pushed
the
fix-7993-pygrass-raster-abstract-exceptions
branch
from
October 3, 2026 12:01
e40221a to
c90d4c5
Compare
Contributor
Author
echoix
approved these changes
Oct 18, 2026
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.
Description
This PR fixes exception handling in
RasterAbstractBaseinpython/grass/pygrass/raster/abstract.py:RasterAbstractBase.set_region()andset_region_from_rast(), replacesfatal()and bareraisecalls withraise GrassError(...)when region modification is attempted on an open raster map.RasterAbstractBase.__getitem__(), replacesfatal("Invalid argument type.")withraise TypeError(...)when an unsupported index type is provided.fatalimport fromgrass.script.python/grass/pygrass/raster/testsuite/test_pygrass_raster.py.Motivation and context
As a library module,
pygrassclasses should raise standard Python exceptions rather than callinggrass.script.fatal()(which abruptly terminates the Python session/process viasys.exit(1)) or executing bareraisestatements outside of active exception handlers.Fixes #7993.
How has this been tested?
Added unit tests in
python/grass/pygrass/raster/testsuite/test_pygrass_raster.pyverifying:RasterRow.set_region()andRasterRow.set_region_from_rast()raiseGrassErrorwhen called on an open raster map.RasterRow.__getitem__()raisesTypeErrorwhen indexed with an invalid key type.Screenshots (if appropriate)
N/A
Types of changes
Checklist