grass icon indicating copy to clipboard operation
grass copied to clipboard

[Bug] Temporal Framework Python interface does not take into account changes of mapset

Open lrntct opened this issue 5 years ago • 8 comments

Describe the bug When changing the mapset inside a Python script, the temporal framework does not take this change into account and fail to connect to the temporal database, even thought GRASS reports the new mapset as being accessible.

To Reproduce

#!/usr/bin/env python3
# -*- coding: utf-8 -*-

import tempfile

import grass_session
import grass.script as gscript

session = grass_session.Session()
tmpdir = tempfile.mkdtemp()
session.open(gisdb=tmpdir,
             location='xy',
             mapset=None,
             create_opts='XY',
             loadlibs=True)

import grass.temporal as tgis

def do_something():
    tgis.init()
    tlist = gscript.read_command('t.list')
    print(tlist)

gscript.run_command('g.mapset', mapset='test1', flags='c')
print(gscript.read_command('g.mapset', flags='p'))
print(gscript.read_command('g.mapsets', flags='p'))
do_something()

gscript.run_command('g.mapset', mapset='test2', flags='c')
print(gscript.read_command('g.mapset', flags='p'))
print(gscript.read_command('g.mapsets', flags='p'))
do_something()

Output:


Loading libraries from /usr/lib/grass78/lib
Mapset switched. Your shell continues to use the history for the old mapset
You can switch the history by commands:
history -w; history -r /tmp/tmp7dc70ya4/xy/test1/.bash_history;
HISTFILE=/tmp/tmp7dc70ya4/xy/test1/.bash_history
test1

Accessible mapsets:
test1 PERMANENT

Default TGIS driver / database set to:
driver: sqlite
database: $GISDBASE/$LOCATION_NAME/$MAPSET/tgis/sqlite.db
WARNING: Temporal database connection defined as:
         /tmp/tmp7dc70ya4/xy/test1/tgis/sqlite.db
         But database file does not exist.
Creating temporal database: /tmp/tmp7dc70ya4/xy/test1/tgis/sqlite.db
----------------------------------------------

Mapset switched. Your shell continues to use the history for the old mapset
You can switch the history by commands:
history -w; history -r /tmp/tmp7dc70ya4/xy/test2/.bash_history;
HISTFILE=/tmp/tmp7dc70ya4/xy/test2/.bash_history
test2

Accessible mapsets:
test2 PERMANENT

Default TGIS driver / database set to:
driver: sqlite
database: $GISDBASE/$LOCATION_NAME/$MAPSET/tgis/sqlite.db
ERROR: Unable to execute sql statement. You have no permission to access
mapset <test2>, or mapset <test2> has no temporal database. Accessible
mapsets are: <test1>

Expected behavior I would expect the GRASS temporal framework to take into account the changes of the current mapset. This could be circumvented by the use of subprocess, but it is not convenient.

System description (please complete the following information):

  • Operating System: Ubuntu 20.04
  • GRASS GIS version: 7.8.2

Additional context Perhaps related: https://trac.osgeo.org/grass/ticket/2110 https://trac.osgeo.org/grass/ticket/3668

lrntct avatar May 12 '20 20:05 lrntct