Skip to content

lib: fix incorrect backend detection in get_backend() - #7240

Open
Photon079 wants to merge 3 commits into
OSGeo:mainfrom
Photon079:fix/get-backend-bug
Open

Photon079 wants to merge 3 commits into
OSGeo:mainfrom
Photon079:fix/get-backend-bug

Conversation

@Photon079

Copy link
Copy Markdown

Previously, get_backend() returned "ipyleaflet" when folium import failed, without validating whether the object was actually an ipyleaflet.Map. This could lead to incorrect backend selection and failures in layer operations.

This fix:

  • Properly checks object types for both folium and ipyleaflet
  • Raises clear ValueError when neither backend matches
  • Adds comprehensive tests covering all edge cases
  • Follows GRASS coding standards

This issue was discovered while writing tests for grass.jupyter as part of the GSoC test-of-skills tasks. I have also opened issue #7239 for tracking this bug.

Previously, get_backend() would return 'ipyleaflet' whenever folium import
failed, without checking if the object was an ipyleaflet.Map.
This could cause crashes in Layer.add_to() methods when wrong backend
was selected.

This fix:
- Properly checks object types for both folium and ipyleaflet
- Raises clear ValueError when neither backend matches
- Adds comprehensive tests covering all edge cases
- Follows GRASS coding standards

Bug discovered while writing tests - original logic made dangerous
assumptions that could break map functionality.

AI assistance used for codebase understanding and test design.
All code changes and testing were performed by the contributor.
@Photon079 Photon079 changed the title Fix incorrect backend detection in get_backend() when imports fail python.jupyter: fix incorrect backend detection in get_backend() Mar 30, 2026
@github-actions github-actions Bot added Python Related code is in Python libraries tests Related to Test Suite notebook labels Mar 30, 2026
@Photon079 Photon079 changed the title python.jupyter: fix incorrect backend detection in get_backend() lib: fix incorrect backend detection in get_backend() Mar 30, 2026

@petrasovaa petrasovaa left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Please use pre-commit to fix any formatting.

Comment thread python/grass/jupyter/interactivemap.py Resolved
Comment thread python/grass/jupyter/interactivemap.py Resolved
@Photon079

Copy link
Copy Markdown
Author

hey @petrasovaa thank you for reviewing , i am working on these things and will update soon

* Skip tests gracefully when mapping libraries are missing
* Update ValueError exception message wording
* Fix docstring alignment in get_backend()
@Photon079
Photon079 force-pushed the fix/get-backend-bug branch from 2608440 to df5731d Compare April 8, 2026 19:27
@Photon079

Copy link
Copy Markdown
Author

Hey @petrasovaa, thanks for the review! I've pushed updates to address your feedback:

Used pytest.importorskip so tests skip gracefully if the mapping libraries are missing.
Fixed the misaligned docstring and successfully ran pre-commit.
Clarified the ValueError message to point out the unsupported backend object type

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

libraries notebook Python Related code is in Python tests Related to Test Suite

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants