Skip to content

grass.temporal: set backend when init() skips database creation#7671

Closed
gkneighb wants to merge 1 commit into
OSGeo:mainfrom
gkneighb:fix-tgis-init-skip-db-backend
Closed

grass.temporal: set backend when init() skips database creation#7671
gkneighb wants to merge 1 commit into
OSGeo:mainfrom
gkneighb:fix-tgis-init-skip-db-backend

Conversation

@gkneighb

Copy link
Copy Markdown
Contributor

Summary

init(skip_db_init=True) returned before setting the tgis_backend global, so get_tgis_backend() was None after it — even though init()'s own docstring documents that skip_db_init still provides "the global TGIS state (backend, mapset, interfaces)".

The regression test grass_temporal_core_init_skip_db_test.py::test_init_succeeds_without_db_creation asserts get_tgis_backend() == "sqlite", but that only held when its sibling test_init_creates_tgis_db_if_not_skipped ran first in the same process and set the global via a full init(). Run standalone, or split across pytest-xdist workers, it failed with assert None == 'sqlite'.

Fix

Set the backend before the early return, reading the driver name non-destructively through the C-library interface (not t.connect, whose -c flag would write the connection VAR) and defaulting to sqlite when no temporal connection is defined yet. This preserves the no-side-effect guarantee of skip_db_init (the same test still asserts not var_file.exists() and not tgis_db.exists()) while honoring the documented contract, so the test passes in isolation and under parallel execution.

How this was found

The failure surfaced on the macOS CI of an unrelated temporal PR (#7670): adding test files shifted pytest-xdist's worker distribution so the two sibling tests landed in different workers, exposing this latent ordering dependency. It reproduces on main with pytest .../grass_temporal_core_init_skip_db_test.py -n 2.

Test plan

Previously failed standalone and under xdist; now passes:

pytest python/grass/temporal/tests/grass_temporal_core_init_skip_db_test.py -n 2

Full temporal regression under parallel execution (139 passed):

pytest python/grass/temporal/tests/ temporal/*/tests/ -n auto

AI assistance

Implemented with the assistance of an AI coding assistant (Claude), reviewed and verified by the author.

init(skip_db_init=True) returned before setting the tgis_backend global,
so get_tgis_backend() was None even though the docstring documents that
skip_db_init still provides the backend. The test
test_init_succeeds_without_db_creation only passed when a sibling test had
already run a full init() in the same process to set the global; run
standalone or split across pytest-xdist workers it failed with
"assert None == 'sqlite'".

Set the backend before the early return by reading the driver name
non-destructively (via the C-library interface, not t.connect, which would
write the connection VAR) and defaulting to sqlite when no temporal
connection is defined. This preserves the no-side-effect guarantee of
skip_db_init (no VAR file, no database created) while honoring the
documented contract, so the test passes in isolation and under parallel
execution.

Test Plan:

Previously failed standalone and under pytest-xdist; now passes:

```
pytest python/grass/temporal/tests/grass_temporal_core_init_skip_db_test.py -n 2
```

Full temporal regression under parallel execution (139 passed):

```
pytest python/grass/temporal/tests/ temporal/*/tests/ -n auto
```

Authored with the help of an AI assistant.
@echoix

echoix commented Jul 12, 2026

Copy link
Copy Markdown
Member

@ninsbl I think you had a PR prepared on your fork for addressing that issue

@echoix echoix requested a review from ninsbl July 12, 2026 04:18

@ninsbl ninsbl left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Good catch.
Still, I would rather solve this as part of #7672 (where I solved it slightly different).

While the solution here is OK and would use a more meaningful default if a TGIS DB connection is defined in the current mapset, I think it is unnecessary to get the defaults from the current mapset, because if the SQL connection gets initialized the defaults in the globals will be overwritten anyway...

@ninsbl

ninsbl commented Jul 13, 2026

Copy link
Copy Markdown
Member

Solved as part of #7672, but again thanks for the effort. We continue the discussion on #7670

@ninsbl ninsbl closed this Jul 13, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

libraries Python Related code is in Python

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants