From 06a52d917888f244b134586b5ecd4d928a86e906 Mon Sep 17 00:00:00 2001 From: ninsbl Date: Sat, 5 Sep 2026 23:53:41 +0200 Subject: [PATCH 1/7] remove hack for connecting only current mapset --- python/grass/temporal/register.py | 49 +++++++++++++++++++------------ 1 file changed, 30 insertions(+), 19 deletions(-) diff --git a/python/grass/temporal/register.py b/python/grass/temporal/register.py index 4edb7f4d20f..f6202c34f2a 100644 --- a/python/grass/temporal/register.py +++ b/python/grass/temporal/register.py @@ -20,7 +20,12 @@ import grass.script as gs from .abstract_map_dataset import AbstractMapDataset -from .core import get_current_mapset, get_tgis_message_interface, init_dbif +from .core import ( + get_current_mapset, + get_tgis_message_interface, + init_dbif, + SQLDatabaseInterfaceConnection, +) from .datetime_math import ( check_datetime_string, increment_datetime_by_string, @@ -33,15 +38,15 @@ def register_maps_in_space_time_dataset( - type, - name, + type: str, + name: str | None = None, maps=None, file=None, start=None, end=None, unit=None, increment=None, - dbif=None, + dbif: SQLDatabaseInterfaceConnection | None = None, interval: bool = False, fs: str = "|", update_cmd_list: bool = True, @@ -72,7 +77,8 @@ def register_maps_in_space_time_dataset( :param increment: Time increment between maps for time stamp creation (format absolute: NNN seconds, minutes, hours, days, weeks, months, years; format relative: 1.0) - :param dbif: The database interface to be used + :param dbif: The database interface to be used (deprecated, + will be removed in future versions) :param interval: If True, time intervals are created in case the start time and an increment is provided :param fs: Field separator used in input file @@ -117,17 +123,21 @@ def register_maps_in_space_time_dataset( if not maps and not file: msgr.fatal(_("Please specify maps or file")) - # We may need the mapset + if dbif is not None: + msgr.warning( + _( + "The dbif argument is deprecated and will be removed in future " + "versions. The database connection will be created automatically" + "only for the current mapset." + ) + ) + # Create a new DB connection only for the current mapset mapset = get_current_mapset() - dbif, connection_state_changed = init_dbif(dbif) - - # create new stds only in the current mapset - # remove all connections to any other mapsets - # ugly hack ! - currcon = {mapset: dbif.connections[mapset]} - dbif.connections = currcon + dbif = SQLDatabaseInterfaceConnection(mapsets=mapset) + dbif.connect() # The name of the space time dataset is optional + sp = None if name: sp = open_old_stds(name, type, dbif) @@ -175,7 +185,7 @@ def register_maps_in_space_time_dataset( # Check if last column is an end time or a semantic label. # Relative timestamps are integers, absolute timestamps are # datetime strings; anything else is a semantic label. - if sp.is_time_relative(): + if sp is not None and sp.is_time_relative(): try: int(line_list[2]) except ValueError: @@ -251,6 +261,7 @@ def register_maps_in_space_time_dataset( map_object_layer = map_object.get_layer() map_object_type = map_object.get_type() if not map_object.map_exists(): + dbif.close() msgr.fatal( _("Unable to update {t} map <{mid}>. The map does not exist.").format( t=map_object_type, mid=map_object_id @@ -277,7 +288,7 @@ def register_maps_in_space_time_dataset( msgr.fatal( _( "Unable to register {t} map <{mid}> with " - "layer {l}. The map has timestamp and " + "layer {l}. The map has no timestamp and " "the start time is not set." ).format( t=map_object_type, @@ -297,8 +308,10 @@ def register_maps_in_space_time_dataset( # We need to check if the time is absolute and the unit was specified time_object = check_datetime_string(start) if isinstance(time_object, datetime) and unit: + dbif.close() msgr.fatal(_("unit can only be set for relative time")) if not isinstance(time_object, datetime) and not unit: + dbif.close() msgr.fatal(_("unit must be set in case of relative time stamps")) if unit: @@ -375,8 +388,7 @@ def register_maps_in_space_time_dataset( # Try to read an existing time stamp from the grass spatial database # in case this map wasn't already registered in the temporal database # Read the spatial database time stamp only, if no time stamp was provided for - # this map - # as method argument or in the input file + # this map as method argument or in the input file if not is_in_db and not start: map_object.read_timestamp_from_grass() @@ -457,8 +469,7 @@ def register_maps_in_space_time_dataset( ds.select(dbif) ds.update_from_registered_maps(dbif) - if connection_state_changed is True: - dbif.close() + dbif.close() msgr.percent(num_maps, num_maps, 1) From e585ab434cf124577da243d3a02141d4331bac3f Mon Sep 17 00:00:00 2001 From: ninsbl Date: Sat, 5 Sep 2026 23:55:09 +0200 Subject: [PATCH 2/7] remove hack for connecting only current mapset --- temporal/t.unregister/t.unregister.py | 30 +++++++++++---------------- 1 file changed, 12 insertions(+), 18 deletions(-) diff --git a/temporal/t.unregister/t.unregister.py b/temporal/t.unregister/t.unregister.py index 990c90952c0..7493ec3ac49 100755 --- a/temporal/t.unregister/t.unregister.py +++ b/temporal/t.unregister/t.unregister.py @@ -62,19 +62,13 @@ def main(): if not maps and not file: gs.fatal(_("%s= or %s= must be specified") % ("input", "file")) - mapset = gs.gisenv()["MAPSET"] + mapset = tgis.get_current_mapset() - dbif = tgis.SQLDatabaseInterfaceConnection() + dbif = tgis.SQLDatabaseInterfaceConnection(mapsets=mapset) dbif.connect() - # modify a stds only if it is in the current mapset - # remove all connections to any other mapsets - # ugly hack ! - currcon = {} - currcon[mapset] = dbif.connections[mapset] - dbif.connections = currcon - # In case a space time dataset is specified + sp = None if input: sp = tgis.open_old_stds(input, type, dbif) @@ -84,7 +78,7 @@ def main(): # Map names as comma separated string if maps is not None and maps != "": - maplist = [maps] if maps.find(",") == -1 else maps.split(",") + maplist = maps.split(",") # Build the maplist for count in range(len(maplist)): @@ -117,30 +111,30 @@ def main(): if count % 10 == 0: gs.percent(count, num_maps, 1) - map = tgis.dataset_factory(type, mapid) + map_item = tgis.dataset_factory(type, mapid) # Unregister map if in database - if map.is_in_db(dbif, mapset=mapset): + if map_item.is_in_db(dbif, mapset=mapset): # Unregister from a single dataset if input: # Collect SQL statements - statement += sp.unregister_map(map=map, dbif=dbif, execute=False) + statement += sp.unregister_map(map=map_item, dbif=dbif, execute=False) # Unregister from temporal database else: # We need to update all datasets after the removement of maps - map.metadata.select(dbif) - datasets = map.get_registered_stds(dbif) + map_item.metadata.select(dbif) + datasets = map_item.get_registered_stds(dbif) # Store all unique dataset ids in a dictionary if datasets: for dataset in datasets: update_dict[dataset] = dataset # Collect SQL statements - statement += map.delete(dbif=dbif, update=False, execute=False) + statement += map_item.delete(dbif=dbif, update=False, execute=False) else: gs.warning( _("Unable to find %s map <%s> in temporal database") - % (map.get_type(), map.get_id()) + % (map_item.get_type(), map_item.get_id()) ) count += 1 @@ -157,7 +151,7 @@ def main(): else: gs.message(_("Unregister maps from the temporal database")) - if input: + if input and sp is not None: sp.update_from_registered_maps(dbif) sp.update_command_string(dbif=dbif) elif len(update_dict) > 0: From 6e628be1b363b6f34977b51dda1ba1bfca6816d0 Mon Sep 17 00:00:00 2001 From: ninsbl Date: Sun, 6 Sep 2026 14:53:34 +0200 Subject: [PATCH 3/7] remove usage of dbif --- python/grass/temporal/register.py | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/python/grass/temporal/register.py b/python/grass/temporal/register.py index f6202c34f2a..28470f6862c 100644 --- a/python/grass/temporal/register.py +++ b/python/grass/temporal/register.py @@ -653,7 +653,10 @@ def register_map_object_list( output_stds_id = output_stds.get_id() if output_stds else None register_maps_in_space_time_dataset( - type, output_stds_id, unit=unit, file=filename, dbif=dbif + type, + output_stds_id, + unit=unit, + file=filename, ) # Remove empty maps and unregister them from the temporal database From 3ffc7fb1ccbcc5be2833775e4352732d1ddf41e0 Mon Sep 17 00:00:00 2001 From: ninsbl Date: Sun, 6 Sep 2026 14:53:58 +0200 Subject: [PATCH 4/7] remove usage of dbif --- python/grass/temporal/stds_import.py | 1 - 1 file changed, 1 deletion(-) diff --git a/python/grass/temporal/stds_import.py b/python/grass/temporal/stds_import.py index dbc918e44bd..8dbee12387c 100644 --- a/python/grass/temporal/stds_import.py +++ b/python/grass/temporal/stds_import.py @@ -613,7 +613,6 @@ def import_stds( start="file", end="file", unit=relative_time_unit, - dbif=None, fs=fs, update_cmd_list=False, ) From a912b926cbf9786e48888292b0991d6f5d0c93e9 Mon Sep 17 00:00:00 2001 From: ninsbl Date: Sun, 6 Sep 2026 14:54:23 +0200 Subject: [PATCH 5/7] remove usage of dbif --- python/grass/temporal/testsuite/test_register_function.py | 2 -- 1 file changed, 2 deletions(-) diff --git a/python/grass/temporal/testsuite/test_register_function.py b/python/grass/temporal/testsuite/test_register_function.py index e8d06f6681e..3b6e9f3e933 100644 --- a/python/grass/temporal/testsuite/test_register_function.py +++ b/python/grass/temporal/testsuite/test_register_function.py @@ -316,7 +316,6 @@ def test_history_raster(self) -> None: start="2001-01-01 10:30:01", increment="1 year", interval=True, - dbif=self.dbif, ) map_1 = tgis.RasterDataset("elevation@PERMANENT") @@ -340,7 +339,6 @@ def test_history_vector(self) -> None: start="2001-01-01 10:30:01", increment="1 year", interval=True, - dbif=self.dbif, ) map_1 = tgis.VectorDataset("lakes@PERMANENT") From 6ed7b2f0e2a70a5c7e1febfeee004898b11819dc Mon Sep 17 00:00:00 2001 From: ninsbl Date: Sun, 6 Sep 2026 14:54:41 +0200 Subject: [PATCH 6/7] remove usage of dbif --- temporal/t.register/t.register.py | 1 - 1 file changed, 1 deletion(-) diff --git a/temporal/t.register/t.register.py b/temporal/t.register/t.register.py index 36e13b23638..653b3a07b46 100755 --- a/temporal/t.register/t.register.py +++ b/temporal/t.register/t.register.py @@ -126,7 +126,6 @@ def main(): end=end, unit=unit, increment=increment, - dbif=None, interval=interval, fs=separator, ) From 232e8fcb37baa5efcce05589906a467e1a255e74 Mon Sep 17 00:00:00 2001 From: ninsbl Date: Sun, 6 Sep 2026 15:02:17 +0200 Subject: [PATCH 7/7] reword deprecation warning --- python/grass/temporal/register.py | 4 +--- 1 file changed, 1 insertion(+), 3 deletions(-) diff --git a/python/grass/temporal/register.py b/python/grass/temporal/register.py index 28470f6862c..348602a9e35 100644 --- a/python/grass/temporal/register.py +++ b/python/grass/temporal/register.py @@ -126,9 +126,7 @@ def register_maps_in_space_time_dataset( if dbif is not None: msgr.warning( _( - "The dbif argument is deprecated and will be removed in future " - "versions. The database connection will be created automatically" - "only for the current mapset." + "The dbif argument is deprecated and will be removed in a future release." ) ) # Create a new DB connection only for the current mapset