Skip to content

temporal: Use temporary GISRC env instead of g.mapset for import#7434

Open
saket0187 wants to merge 2 commits into
OSGeo:mainfrom
saket0187:use-session-stds-import
Open

temporal: Use temporary GISRC env instead of g.mapset for import#7434
saket0187 wants to merge 2 commits into
OSGeo:mainfrom
saket0187:use-session-stds-import

Conversation

@saket0187
Copy link
Copy Markdown
Contributor

This PR tries to address #3132

Replace g.mapset‑based project switching in stds_import.py with a temporary GISRC environment so the user’s session project/mapset does not change during background imports.

@github-actions github-actions Bot added Python Related code is in Python libraries labels May 25, 2026
Copy link
Copy Markdown
Contributor

@petrasovaa petrasovaa left a comment

Choose a reason for hiding this comment

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

This looks good! I think it would be good to add a test covering this particular fix, perhaps in t.rast.import. There is already a unittest we could expand.

@saket0187
Copy link
Copy Markdown
Contributor Author

This looks good! I think it would be good to add a test covering this particular fix, perhaps in t.rast.import. There is already a unittest we could expand.

Hello, I’m a bit confused about how to check the location in the middle of the test. The old code also switched back to the original location at the end, so I’m not sure how to show the difference exactly. Do you have any suggestions?

@petrasovaa
Copy link
Copy Markdown
Contributor

This looks good! I think it would be good to add a test covering this particular fix, perhaps in t.rast.import. There is already a unittest we could expand.

Hello, I’m a bit confused about how to check the location in the middle of the test. The old code also switched back to the original location at the end, so I’m not sure how to show the difference exactly. Do you have any suggestions?

I was just thinking to test the project option ('project' used to be called 'location') that it does what it's supposed to do, you don't need to demonstrate the fix itself, that would be indeed complicated (that's what you meant, right?). So just testing the new project exists should be enough, the current test is not testing that at all. I also noticed the project option has description "Do not run this module in parallel or interrupt it when a new project should be created", I assume that can be removed now.

@saket0187
Copy link
Copy Markdown
Contributor Author

I was just thinking to test the project option ('project' used to be called 'location') that it does what it's supposed to do, you don't need to demonstrate the fix itself, that would be indeed complicated (that's what you meant, right?).

Yes

So just testing the new project exists should be enough, the current test is not testing that at all. I also noticed the project option has description "Do not run this module in parallel or interrupt it when a new project should be created", I assume that can be removed now.

While running the test file test_temporal_rast_import.py, it is giving me some errors. Also, why wasn't:

if __name__ == "__main__":
    from grass.gunittest.main import test
    test()

at the end of the file like the other tests?
After adding this, I'm getting errors on tearDownClass and the old test as well. Maybe we need to fix this whole test file, as it looks like it wasn't running before. I just wanted to confirm before doing that. Can you please check this once?

@petrasovaa
Copy link
Copy Markdown
Contributor

Yes, here is the diff to get it working:

--- a/temporal/t.rast.import/testsuite/test_temporal_rast_import.py
+++ b/temporal/t.rast.import/testsuite/test_temporal_rast_import.py
@@ -12,6 +12,7 @@ for details.
 import os
 
 from grass.gunittest.case import TestCase
+from grass.gunittest.gmodules import SimpleModule
 
 
 class TestRasterImport(TestCase):
@@ -20,12 +21,11 @@ class TestRasterImport(TestCase):
     @classmethod
     def tearDownClass(cls):
         """Remove the temporary region"""
-        cls.del_temp_region()
         cls.runModule("t.remove", flags="df", inputs="A")
 
     def test_import(self):
         self.assertModule(
-            "t.rast.import", input=self.input_, output="A", basename="a", overwrite=True
+            "t.rast.import", flags="o", input=self.input_, output="A", basename="a", overwrite=True
         )
         tinfo = """start_time='2000-01-01 00:00:00'
                    end_time='2001-01-01 00:00:00'
@@ -34,8 +34,13 @@ class TestRasterImport(TestCase):
                    north=320000.0
                    south=10000.0
                    east=935000.0
-                   west=120000.0
-                """
+                   west=120000.0"""
 
-        info = SimpleModule("t.info", flags="g", input="A")
-        self.assertModuleKeyValue(module=info, reference=tinfo, precision=2, sep="=")
+        # info = SimpleModule("t.info", flags="g", input="A")
+        self.assertModuleKeyValue(module="t.info", input="A", flags="g", reference=tinfo, precision=2, sep="=")
+
+
+if __name__ == "__main__":
+    from grass.gunittest.main import test
+
+    test()

@github-actions github-actions Bot added temporal Related to temporal data processing module tests Related to Test Suite labels Jun 2, 2026
@saket0187
Copy link
Copy Markdown
Contributor Author

Hi @petrasovaa ,
I wanted to ask if there is a known bug in t.rast.import when using the project flag. I tried testing that the project is created using this code:

self.assertModule(
    "t.rast.import", 
    flags="o", 
    input=self.input_, 
    output="B", 
    basename="b", 
    project=self.new_project_name, 
    overwrite=True
)

However, the test fails at the very end. I tested this against both the old g.mapset code and the new environment code, and it crashes identically on both with this exact error:
ERROR: Unable to update raster map <b_01@PERMANENT>. The map does not exist.
Am I doing something wrong?

Here is the AI generated summary of error

The error is caused by a core synchronization bug inside the t.rast.import module whenever the project flag is used.
Here is exactly what happens:

- The Success: The module successfully creates the new project, and its background subprocesses correctly extract the raster maps into that new location.
- The Bug: The main Python script's temporal database connection (tgis) gets permanently locked to the original project the moment the script starts up.
- The Crash: At the very end of the script, when Python tries to register the newly extracted maps, it searches the old database cache instead of the new one, fails to find them, and crashes with The map does not exist.

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

Labels

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

Projects

Development

Successfully merging this pull request may close these issues.

2 participants