GeoNode / geoserver-restconfig

geoserver-restconfig is a python library for manipulating a GeoServer instance via the GeoServer RESTConfig API.
MIT License
46 stars 29 forks source link

`overwrite=True` does not update SLD version when re-uploading a style #38

Open fvicent opened 1 year ago

fvicent commented 1 year ago

Describe the bug

You are able to update the content of an existing style by using Catalog.create_style() with overwrite=True, but you can't change the style version (e.g. from 1.0 to 1.1). If the existing style is 1.0 and the new content is 1.1, GeoServer tries to fix the format and completely breaks the XML.

To Reproduce

After a fresh GeoNode installation run the following script:

from geoserver.catalog import Catalog
from pathlib import Path
import time

catalog = Catalog("http://localhost/geoserver/rest")
catalog.create_style(
    "test_style",
    Path("sld10.xml").read_text("utf8"),
    style_format="sld10"
)
time.sleep(10)
catalog.create_style(
    "test_style",
    Path("sld11.xml").read_text("utf8"),
    style_format="sld11",
    overwrite=True
)

sld10.xml:

<?xml version="1.0" encoding="UTF-8"?>
<StyledLayerDescriptor xmlns="http://www.opengis.net/sld" version="1.0.0" xmlns:ogc="http://www.opengis.net/ogc" xmlns:xlink="http://www.w3.org/1999/xlink" xmlns:se="http://www.opengis.net/se" xsi:schemaLocation="http://www.opengis.net/sld http://schemas.opengis.net/sld/1.1.0/StyledLayerDescriptor.xsd" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">
  <NamedLayer>
    <Name>test_layer.shp</Name>
    <UserStyle>
      <Name>test_style</Name>
      <FeatureTypeStyle>
        <Rule>
          <LineSymbolizer>
            <Stroke>
              <CssParameter name="stroke">#e3e3e3</CssParameter>
            </Stroke>
          </LineSymbolizer>
        </Rule>
      </FeatureTypeStyle>
    </UserStyle>
  </NamedLayer>
</StyledLayerDescriptor>

sld11.xml:

<?xml version="1.0" encoding="UTF-8"?>
<StyledLayerDescriptor xmlns="http://www.opengis.net/sld" version="1.1.0" xmlns:ogc="http://www.opengis.net/ogc" xmlns:xlink="http://www.w3.org/1999/xlink" xmlns:se="http://www.opengis.net/se" xsi:schemaLocation="http://www.opengis.net/sld http://schemas.opengis.net/sld/1.1.0/StyledLayerDescriptor.xsd" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">
  <NamedLayer>
    <se:Name>test_layer.shp</se:Name>
    <UserStyle>
      <se:Name>test_style</se:Name>
      <se:FeatureTypeStyle>
        <se:Rule>
          <se:LineSymbolizer>
            <se:Stroke>
              <se:SvgParameter name="stroke">#e3e3e3</se:SvgParameter>
            </se:Stroke>
          </se:LineSymbolizer>
        </se:Rule>
      </se:FeatureTypeStyle>
    </UserStyle>
  </NamedLayer>
</StyledLayerDescriptor>

You will note the style version is still 1.0:

geoserver-styles

But the content was replaced and reverted to 1.0, and now is broken:

geoserver-style-content