Skip to content

replace typehint operator by union to be stable for older python vers#163

Merged
signedav merged 2 commits intomainfrom
fix-python-typeunion
Jan 29, 2026
Merged

replace typehint operator by union to be stable for older python vers#163
signedav merged 2 commits intomainfrom
fix-python-typeunion

Conversation

@signedav
Copy link
Member

No description provided.

@signedav signedav requested a review from gacarrillor January 26, 2026 10:37
@signedav
Copy link
Member Author

Strange that the latest version tests are failing. It seems that with

 [l.name() for l in root.children() if isinstance(l, QgsLayerTreeLayer)]

Not only the main group layers but instead as well the layers in a group are listed. I tried in QGIS and with master and 3.44.3-Solothurn it neither listed the sub-layers :think:

image

@signedav
Copy link
Member Author

I tested it locally and tests are working. testet in in QGIS 3.44.7 directly with this, and working:


import datetime
import logging
import os
import pathlib
import tempfile

from qgis.core import QgsExpressionContextUtils, QgsLayerTreeLayer, QgsProject
from qgis.testing import start_app, unittest

from modelbaker.dataobjects.project import Project
from modelbaker.db_factory.gpkg_command_config_manager import GpkgCommandConfigManager
from modelbaker.iliwrapper import iliimporter
from modelbaker.iliwrapper.globals import DbIliMode
from modelbaker.utils.globals import OptimizeStrategy
from modelbaker.generator.generator import Generator
from modelbaker.iliwrapper.ili2dbconfig import (
    BaseConfiguration,
    DeleteConfiguration,
    ExportConfiguration,
    ExportMetaConfigConfiguration,
    ImportDataConfiguration,
    SchemaImportConfiguration,
    UpdateDataConfiguration,
    ValidateConfiguration,
)

importer = iliimporter.Importer()
importer.tool = DbIliMode.ili2gpkg    
importer.configuration = SchemaImportConfiguration()
importer.configuration.base_configuration = BaseConfiguration()
importer.configuration.ilifile ="/home/dave/dev/opengisch/QgisModelBakerLibrary/tests/testdata/ilimodels/Kantonale_Bauplanung_V1_1.ili"
importer.configuration.ilimodels = "Kantonale_Bauplanung_V1_1"
importer.configuration.dbfile = "tmp_optimal_baustruct_{:%Y%m%d%H%M%S%f}.gpkg".format(
        datetime.datetime.now()
    )
importer.configuration.srs_code = 2056
importer.configuration.inheritance = "smart2"
importer.configuration.create_basket_col = True
print(f"success {importer.run() == iliimporter.Importer.SUCCESS}")

config_manager = GpkgCommandConfigManager(importer.configuration)
uri = config_manager.get_uri()

### 1. OptimizeStrategy.NONE ###
strategy = OptimizeStrategy.NONE

generator = Generator(
    tool=DbIliMode.ili2gpkg,
    uri=uri,
    inheritance=importer.configuration.inheritance,
    optimize_strategy=strategy,
    consider_basket_handling=True,
)

available_layers = generator.layers()
relations, _ = generator.relations(available_layers)
legend = generator.legend(available_layers)
aliases = [l.alias for l in available_layers if l.alias is not None]
irrelevant_layer_ilinames = [
    l.ili_name for l in available_layers if not l.is_relevant
]
ambiguous_aliases = [alias for alias in aliases if aliases.count(alias) > 1]

project = Project(
    optimize_strategy=strategy,
    context={"catalogue_datasetname": 'test'},
)
project.layers = available_layers
project.relations = relations
project.legend = legend
project.post_generate()

qgis_project = QgsProject.instance()
project.create(None, qgis_project)

root = qgis_project.layerTreeRoot()
all_layers = root.findLayers()
geometry_layers = {
    l.name() for l in root.children() if isinstance(l, QgsLayerTreeLayer)
}

I have no idea 🤔

@gacarrillor
Copy link
Member

I have no idea 🤔

Me neither. I also checked the code and don't see any recent change in QgsLayerTreeNode->children().

@signedav
Copy link
Member Author

Merging this. maybe the latest docker build is just broken.

@signedav signedav merged commit d6af796 into main Jan 29, 2026
6 of 7 checks passed
@signedav signedav deleted the fix-python-typeunion branch January 29, 2026 10:58
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants