Skip to content

Commit c53e36f

Browse files
committed
feat: remove attributes elements before featureType insertion to avoid custom attributes checkbox set
1 parent 07d78aa commit c53e36f

File tree

1 file changed

+17
-4
lines changed

1 file changed

+17
-4
lines changed

backend/maelstro/core/copy_manager.py

Lines changed: 17 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@
1313
from maelstro.common.exceptions import ParamError
1414
from .georchestra import GeorchestraHandler
1515
from .operations import raise_for_status
16-
16+
import xml.etree.ElementTree as ET
1717

1818
logger = logging.getLogger()
1919

@@ -356,25 +356,28 @@ def copy_layer(
356356
)
357357
resource = gs_src.rest_client.get(xml_resource_route)
358358

359+
# Clean <attributes> element to avoid "Custom attributes" checkbox being set
360+
# See issue #94
361+
cleaned_content = self.remove_attributes_element(resource.content)
359362
if has_resource.status_code == 200:
360363
if has_layer.status_code != 200:
361364
resp = self.gs_dst.rest_client.delete(resource_route)
362365
raise_for_status(resp)
363366
resp = self.gs_dst.rest_client.post(
364367
resource_post_route,
365-
data=resource.content,
368+
data=cleaned_content,
366369
headers={"content-type": "application/xml"},
367370
)
368371
else:
369372
resp = self.gs_dst.rest_client.put(
370373
xml_resource_route,
371-
data=resource.content,
374+
data=cleaned_content,
372375
headers={"content-type": "application/xml"},
373376
)
374377
else:
375378
resp = self.gs_dst.rest_client.post(
376379
resource_post_route,
377-
data=resource.content,
380+
data=cleaned_content,
378381
headers={"content-type": "application/xml"},
379382
)
380383
if resp.status_code == 404:
@@ -425,3 +428,13 @@ def copy_style(
425428
headers={"content-type": style_def.headers["content-type"]},
426429
)
427430
raise_for_status(dst_style_def)
431+
432+
def remove_attributes_element(self, xml_bytes: bytes) -> Any:
433+
root = ET.fromstring(xml_bytes)
434+
if root is not None:
435+
attributes = root.find("attributes")
436+
if attributes is not None:
437+
root.remove(attributes)
438+
return ET.tostring(root, encoding="utf-8")
439+
# If root is None, return the original bytes or handle as needed
440+
return ET.tostring(root, encoding="utf-8")

0 commit comments

Comments
 (0)