Skip to content

Commit

Permalink
Improve logging when invalid vector layer found
Browse files Browse the repository at this point in the history
  • Loading branch information
Gustry committed May 15, 2024
1 parent 0c36013 commit 706a842
Show file tree
Hide file tree
Showing 2 changed files with 29 additions and 9 deletions.
33 changes: 25 additions & 8 deletions lizmap_server/core.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@

from functools import lru_cache
from pathlib import Path
from typing import Dict, Tuple, Union
from typing import Dict, Optional, Tuple, Union

from qgis.core import (
Qgis,
Expand Down Expand Up @@ -49,25 +49,42 @@ def find_vector_layer_from_params(params, project):
return True, layer


def find_vector_layer(layer_name: str, project: QgsProject) -> Union[None, QgsVectorLayer]:
def find_vector_layer(layer_name: str, project: QgsProject) -> Optional[QgsVectorLayer]:
""" Find vector layer with name, short name or layer id. """
found = None
for layer in project.mapLayers().values():

# only vector layer
if layer.type() != QgsMapLayer.VectorLayer:
continue

# check name
if layer.name() == layer_name:
return layer
found = layer
break

# check short name
if layer.shortName() == layer_name:
return layer
found = layer
break

# check layer id
if layer.id() == layer_name:
return layer
found = layer
break

if not found:
Logger.warning(
"The vector layer '{}' has not been found in the project '{}'".format(layer_name, project.fileName()))
return None

Logger.warning(
"The vector layer '{}' has not been found in the project '{}'".format(layer_name, project.fileName()))
return None
found: QgsVectorLayer
if not found.isValid():
Logger.warning(
f"The vector layer '{layer_name}' has been found but it is not valid in the project "
f"'{project.fileName()}'"
)
return found


def get_server_fid(feature: QgsFeature, pk_attributes: list) -> str:
Expand Down
5 changes: 4 additions & 1 deletion lizmap_server/get_legend_graphic.py
Original file line number Diff line number Diff line change
Expand Up @@ -92,7 +92,10 @@ def responseComplete(self):
return

if not layer.isValid():

logger.warning(
f"Layer '{layer_name}' is not valid, returning a warning icon in the legend for project "
f"'{project.homePath()}'"
)
json_data = {
'title': '',
'nodes': [{
Expand Down

0 comments on commit 706a842

Please sign in to comment.