Skip to content

wxGUI/gmodeler: Correct variable replacement in model_convert.py#7241

Open
gureckyfrantisek wants to merge 6 commits intoOSGeo:mainfrom
gureckyfrantisek:issue-7212
Open

wxGUI/gmodeler: Correct variable replacement in model_convert.py#7241
gureckyfrantisek wants to merge 6 commits intoOSGeo:mainfrom
gureckyfrantisek:issue-7212

Conversation

@gureckyfrantisek
Copy link
Copy Markdown

I found the issue which caused the previous variable in the same string not get recognized.

The issue was that when another match was found, the old value got replaced instead of the updated one called "parametrizedValue".

Also made the curly braces around variable names optional, they get recognized correctly but leaving them mandatory should be readable, that is up for debate.

I tested this with r.in.pdal and a *.laz file and the import worked as expected with both the values replaced with options.

This will resolve #7212.

@github-actions github-actions Bot added GUI wxGUI related Python Related code is in Python labels Mar 30, 2026
@gureckyfrantisek gureckyfrantisek changed the title fix: Correct variable replacement wxGUI/gmodeler: Correct variable replacement in model_convert.py Mar 31, 2026
@landam landam added this to the 8.5.0 milestone Apr 7, 2026
@landam landam requested review from landam and pesekon2 April 7, 2026 06:18
for var in variables["vars"]:
pattern = re.compile("%{" + var + "}")
found = pattern.search(value)
# curly braces are optional
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.

Curly braces enclosing variables were introduced in version 8.5. I assumed this change was meant to ensure backward compatibility, which would be nice. I tested to load model without braces (attached in the issue), the conversion to Python works. But attempt to run the model (directly from the modeler, not converted Python code) fails - no variables are substituted.

p.in.pdal -e -o --overwrite input=%path/dmp1g/%tile.laz output=%tile_dmp method=mean type=FCELL zscale=1.0 iscale=1.0 resolution=%resolution dimension=z
...

Backward compatibility wasn’t explicitly mentioned in the issue. I think it’s fine to keep this change in the PR, but in that case the model execution should be fixed as well.

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

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

With the latest commits I changed every re.compile in the gmodeler folder have optional curly braces.

I managed to both run the model directly and have the values parametrized in the generated python code, but I had a leftover empty raster in my map at the end of the process:

Failed to run command 'd.rast map=%tile_chm'. Details:

GRASS_INFO_ERROR(70582,1): Raster map <%tile_chm> not found
GRASS_INFO_END(70582,1)
Failed to run command 'd.rast map=%tile_chm'. Details:

GRASS_INFO_ERROR(70665,1): Raster map <%tile_chm> not found
GRASS_INFO_END(70665,1)

I couldn't see, where the d.rast function is called, it's not in the model or the python code.

It doesn't break it, so I didn't look for a solution yet.

@landam landam added the bug Something isn't working label Apr 15, 2026
@gureckyfrantisek
Copy link
Copy Markdown
Author

I realized that the regex now allows for a variable to be parametrized as %{tile.laz or %tile}.laz, which works but could be unwanted behavior.

Should I improve the regex based on this realization?

@landam
Copy link
Copy Markdown
Member

landam commented Apr 23, 2026

ealized that the regex now allows for a variable to be parametrized as %{tile.laz or %tile}.laz, which

@gureckyfrantisek Yes, please refine the regex—either adopt curly brace syntax (%{tile}), which is recommended in GRASS 8.5 and newer, or retain the older format (%tile) for compatibility with GRASS 8.4. Nothing between.

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

Labels

bug Something isn't working GUI wxGUI related Python Related code is in Python

Projects

None yet

Development

Successfully merging this pull request may close these issues.

[Bug] Graphical Modeler: multiple variables used in single option are not substituted properly

3 participants