diff --git a/.pre-commit-config.yaml b/.pre-commit-config.yaml index 1c064f5..a13bad6 100644 --- a/.pre-commit-config.yaml +++ b/.pre-commit-config.yaml @@ -16,7 +16,7 @@ repos: hooks: # Run the linter. - id: ruff - args: [ --fix ] + args: [ "--select", "I", "--fix" ] # Run the formatter. - id: ruff-format @@ -27,10 +27,3 @@ repos: hooks: - id: mypy additional_dependencies: [] - - # Sort imports alphabetically - - repo: https://github.com/PyCQA/isort - rev: 6.0.1 - hooks: - - id: isort - args: ["--profile", "black"] diff --git a/libqfieldsync/offliners.py b/libqfieldsync/offliners.py index 0a9c68e..3a66597 100644 --- a/libqfieldsync/offliners.py +++ b/libqfieldsync/offliners.py @@ -10,6 +10,7 @@ Qgis, QgsCoordinateReferenceSystem, QgsCoordinateTransform, + QgsCsException, # type: ignore[import] QgsDataSourceUri, QgsFeatureRequest, QgsField, @@ -113,6 +114,11 @@ def convert_to_offline( if bbox and bbox.isFinite(): only_selected = True for layer in layers: + if layer.type() != QgsMapLayer.LayerType.VectorLayer: + continue + + assert isinstance(layer, QgsVectorLayer) + if Qgis.versionInt() >= 33000: # noqa: PLR2004 no_geometry_types = [ Qgis.GeometryType.Null, @@ -131,8 +137,14 @@ def convert_to_offline( layer.removeSelection() else: tr = QgsCoordinateTransform(project.crs(), layer.crs(), project) - layer_bbox = tr.transform(bbox) - layer.selectByRect(layer_bbox) + + try: + layer_bbox = tr.transform(bbox) + layer.selectByRect(layer_bbox) + except QgsCsException as err: + logger.warning( + f"Failed to transform project CRS {project.crs().authid()} bbox to layer {layer.name()} CRS {layer.crs().authid()} bbox within `QgisCoreOffliner`: {err}. All features will be offlined for this layer." + ) # If the selection by BBOX did not select anything, make sure we fool `QgsOfflineEditing` something is selected. # Otherwise when `layer.selectedFeatureIds().isEmpty()`, `QgsOfflineEditing` dumps all features. @@ -437,8 +449,14 @@ def _convert_to_offline_project( tr = QgsCoordinateTransform( project.crs(), layer_to_offline.crs(), project ) - layer_bbox = tr.transform(bbox) - request.setFilterRect(layer_bbox) + + try: + layer_bbox = tr.transform(bbox) + request.setFilterRect(layer_bbox) + except QgsCsException as err: + logger.warning( + f"Failed to transform project CRS {project.crs().authid()} bbox to layer {layer_to_offline.name()} CRS {layer_to_offline.crs().authid()} bbox within `PythonMiniOffliner`: {err}. All features will be offlined for this layer." + ) if filters_mapping[datasource_hash]: request.setFilterExpression(filters_mapping[datasource_hash])