I am currently blocked by a quite weird issue I have no idea how to solve.

On Windows 10, with QGIS Desktop 3.22.11. The simple process of doing a difference between a linestring and a polygon breaks up my linestring in a multilinestring but a recuperable one since all parts are in order. So its as simple as concatenating all the points of all parts to rebuild the clipped linestring.
[![enter image description here][3]][3]
However running the same difference operation inside a Debian Docker container having installed the same version of QGIS as the windows desktop version gives the following result 
[![enter image description here][2]][2]
which is barelly usable since I need to rebuild the linestring from the multiple parts. 

I am unsure of what exactly causes the change in behavior except that it is consistent and repeatable. And that it is probably caused by how the (self-intersecting) geometry that result from the `QgsGeometry.difference()` operation is built

test code used to generate the geometry:
```lang-python
from qgis.core import QgsVectorLayer

if __name__ == "__main__":
    poly_layer = QgsVectorLayer("poly.gpkg|layername=poly", "poly", "ogr")
    linestring_layer = QgsVectorLayer("linestring.gpkg|layername=linestring", "linestring", "ogr")
else:
    poly_layer = QgsProject.instance().mapLayersByName("poly")[0]
    linestring_layer = QgsProject.instance().mapLayersByName("linestring")[0]

linestring = next(linestring_layer.getFeatures())
poly = next(poly_layer.getFeatures())

diff = linestring.geometry().difference(poly.geometry())

print(diff.asWkt())

for geom in diff.constParts():
    print(geom.asWkt())
# # or
#for geom in diff.asGeometryCollection():
#    print(geom.asWkt())
```


  [2]: https://i.sstatic.net/8GtUI.png
  [3]: https://i.sstatic.net/OGAbe.png