Skip to content

v.db.addtable: Expand $MAP anywhere in the database path - #8112

Open
alteralto wants to merge 2 commits into
OSGeo:mainfrom
alteralto:fix-8106-addtable-map
Open

alteralto wants to merge 2 commits into
OSGeo:mainfrom
alteralto:fix-8106-addtable-map

Conversation

@alteralto

@alteralto alteralto commented Oct 25, 2026 •

Copy link
Copy Markdown

v.db.addtable replaced only $MAP/ in the database path, so a per-map database named after the map, such as $GISDBASE/$LOCATION_NAME/$MAPSET/sqlite/$MAP.db, reached db.tables with $MAP still in it and the tool failed with "Unable to describe table".

$MAP is now replaced wherever it appears, as Vect_subst_var() and pygrass do. $MAPSET is left for the driver to expand: the library substitutes it before $MAP, and the script now skips it explicitly, which is what the trailing slash used to guard against.

The new pytest test (scripts/v.db.addtable/tests/, using xy_empty_dataset_session) adds a table to a fresh vector for two connections, sqlite/$MAP.db and the existing vector/$MAP/sqlite.db, and checks the column and the database file.

Tested in the osgeo/grass-gis:main-alpine image (8.6.0dev): on main the sqlite/$MAP.db case fails with the db.tables error from the issue and the vector/$MAP/sqlite.db case passes; with this change both pass. The reproducer from the issue also works, and so does the default sqlite/sqlite.db connection.

Fixes #8106

The script replaced only "$MAP/", so a per-map database such as
$GISDBASE/$LOCATION_NAME/$MAPSET/sqlite/$MAP.db reached db.tables
unexpanded and the tool failed. Replace $MAP wherever it appears, as
Vect_subst_var() does, while leaving $MAPSET alone.

Fixes OSGeo#8106
@github-actions github-actions Bot added vector Related to vector data processing Python Related code is in Python module tests Related to Test Suite labels Oct 25, 2026
@alteralto
alteralto marked this pull request as ready for review October 25, 2026 22:47
@nilason

nilason commented Oct 25, 2026

Copy link
Copy Markdown
Contributor

The test needs no sample data, so it belongs in pytest rather than the
gunittest testsuite. It covers the sqlite/$MAP.db form from OSGeo#8106 and
the vector/$MAP/sqlite.db form that already worked.
@alteralto

Copy link
Copy Markdown
Author

I now checked this md doc again. Thanks for the pointer. When you looked, the description still said I was running the tests; they're done now, and I've reworked the test to follow the guide: it's pytest in scripts/v.db.addtable/tests/ (with xy_empty_dataset_session), since it needs no sample data, and the testsuite change is reverted. It covers the sqlite/$MAP.db form from the issue and the vector/$MAP/sqlite.db form that already worked. In the osgeo/grass-gis:main-alpine image the first case fails on main with the db.tables error from the issue, and both pass with this change. If you meant something else in CONTRIBUTING let me know please

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

Labels

module Python Related code is in Python tests Related to Test Suite vector Related to vector data processing

Projects

None yet

Development

Successfully merging this pull request may close these issues.

[Bug] v.db.addtable expands $MAP only when it is a directory

2 participants