From 7506d85897a4f12e5cf366516c5b9afe4292a718 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Johannes=20Kr=C3=B6ger?= Date: Thu, 25 Apr 2024 11:48:11 +0200 Subject: [PATCH] Use "id" as sentinel for discovering workspace specific settings --- geocatbridge/servers/models/geoserver.py | 30 +++++++----------------- 1 file changed, 8 insertions(+), 22 deletions(-) diff --git a/geocatbridge/servers/models/geoserver.py b/geocatbridge/servers/models/geoserver.py index c752c3a..0b0aa31 100644 --- a/geocatbridge/servers/models/geoserver.py +++ b/geocatbridge/servers/models/geoserver.py @@ -1110,32 +1110,18 @@ def clearWorkspace(self, recreate=True) -> bool: else: raise - # Get settings override + # Get workspace specific settings url = f"{self.apiUrl}/workspaces/{self.workspace}/settings.json" workspace_settings = self.request(url).json() # GeoServer returns *some* settings even if the workspace does not use any Workspace Specific Settings: # https://osgeo-org.atlassian.net/browse/GEOS-11361 - # Here we check if we got those exact settings and if so, consider them to mean "no settings". - # As of GeoServer 2.24.2: - default_workspace_settings = { - "settings": { - "contact": {"id": "contact"}, - "charset": 'UTF-8', - "numDecimals": 4, - "verbose": False, - "verboseExceptions": False, - "localWorkspaceIncludesPrefix": False, - "showCreatedTimeColumnsInAdminList": False, - "showModifiedTimeColumnsInAdminList": False - } - } - if workspace_settings == default_workspace_settings: - self.logWarning( - "Received *default* workspace specific settings which indicates " - "that there were no *actual* settings. " - "Setting the workspace to have *no* workspace specific settings." - ) - workspace_settings = {} + # The presence of an "id" key denotes if there are any *actual* workspace specific settings + if workspace_settings.get("settings", {}).get("id"): + # We want GeoServer to be able to recreate the "id" if necessary + del workspace_settings["settings"]["id"] + # Apart from that, we can use the acquired dict to initialise the "new" workspace + else: + workspace_settings = None # Delete workspace recursively url = f"{self.apiUrl}/workspaces/{self.workspace}.json?recurse=true"