Skip to content

temporal: add parameter to skip creation of TGIS DB in current mapset on tgis.init - #7645

Merged
ninsbl merged 11 commits into
OSGeo:mainfrom
ninsbl:skip_db_init
Jul 7, 2026
Merged

ninsbl merged 11 commits into
OSGeo:mainfrom
ninsbl:skip_db_init

Conversation

@ninsbl

@ninsbl ninsbl commented Jul 7, 2026

Copy link
Copy Markdown
Member

Some temporal tools (like t.list, t.rast.list, t.info, ...) do not need to write to a TGIS database. For those modules, it would make sense if tgis.init() not allways forces the creation of a TGIS DB in the current mapset.

This PR adds a parameter so DB creation can be skipped. The current behavior is unchanged, as skipping TGIS DB creation has to be explicitly requested.

A regression test is added to test that both alternatives work as expected.

@ninsbl ninsbl added this to the 8.6.0 milestone Jul 7, 2026
@ninsbl

ninsbl commented Jul 7, 2026

Copy link
Copy Markdown
Member Author

This is a library change as a foundation for fixing: #7576
It should be merged before: #7631

@ninsbl
ninsbl requested review from echoix and petrasovaa July 7, 2026 10:58
@ninsbl ninsbl added temporal Related to temporal data processing Python Related code is in Python libraries tests Related to Test Suite enhancement New feature or request labels Jul 7, 2026

@echoix echoix 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.

Quick review, assuming tests will pass

@ninsbl
ninsbl enabled auto-merge (squash) July 7, 2026 12:20
@ninsbl
ninsbl merged commit 8eb0a03 into OSGeo:main Jul 7, 2026
26 checks passed
@echoix

echoix commented Jul 10, 2026 •

Copy link
Copy Markdown
Member

I saw a failure in a PR, on macOS, on one of these new tests, that might be because the success of this test is either order of execution dependent, or is impacted by other tests running in parallel. It is probably not isolated enough to fail only in intended cases.

See https://github.com/OSGeo/grass/actions/runs/29107259300/job/86410721891?pr=7635

@echoix

echoix commented Jul 10, 2026

Copy link
Copy Markdown
Member

Just tried if copilot has an intelligent idea or not, I'm not sure it actually looked at the code that is tested by its response:

Solution for Failing Job

Problem

The test test_init_succeeds_without_db_creation is failing with:

AssertionError: assert None == 'sqlite'
where None = <function get_tgis_backend at 0x114e55d00>()

The issue is on line 71 of the test file. When tgis.init(skip_db_init=True) is called, the function tgis.get_tgis_backend() is returning None instead of the expected "sqlite".

Root Cause

When skip_db_init=True is passed to tgis.init(), the temporal GIS backend is not being properly initialized. The backend detection logic depends on the database initialization that's being skipped, causing get_tgis_backend() to return None.

Solution

The test's expectation is incorrect. When database initialization is skipped, the backend should not be queried or the assertion should be conditional. Here's the recommended fix:

Option 1: Skip the backend assertion when DB init is skipped (Recommended)

def test_init_succeeds_without_db_creation(simple_mapset):
    """tgis.init(skip_db_init=True) does not create a DB or connection entry in VAR."""
    project_c = simple_mapset
    var_file = Path(project_c) / "VAR"
    tgis_db = Path(project_c) / "tgis"
    with gs.setup.init(project_c):
        tgis.init(skip_db_init=True)
        first_ciface = tgis.get_tgis_c_library_interface()
        assert first_ciface.available_mapsets() == ["c", "PERMANENT"]
        assert tgis.get_tgis_version() == 2
        # Don't assert backend when DB initialization is skipped
        # assert tgis.get_tgis_backend() == "sqlite"
        assert tgis.get_enable_mapset_check() is True
        assert tgis.get_enable_timestamp_write() is True
        assert tgis.get_sql_template_path().endswith("sql")
        assert not var_file.exists()
        assert not tgis_db.exists()

Option 2: Allow None as a valid return value

# At line 71, change:
assert tgis.get_tgis_backend() == "sqlite"

# To:
backend = tgis.get_tgis_backend()
assert backend is None or backend == "sqlite"  # Accept None when DB init is skipped

Option 3: Ensure backend is initialized even without DB

If the backend should always be available, modify the tgis.init() function to initialize the backend even when skip_db_init=True.

Recommended Action: Use Option 1 - remove the backend assertion from the skip_db_init=True test case, as it's semantically inconsistent to skip database initialization yet expect the backend to be fully initialized.

@ninsbl

ninsbl commented Jul 10, 2026

Copy link
Copy Markdown
Member Author

Thanks for the heads up @echoix . I encountered a similar situation. I am preparing a new PR here: ninsbl#30 That may fix what you describe too.

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

Labels

enhancement New feature or request libraries Python Related code is in Python temporal Related to temporal data processing tests Related to Test Suite

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants