From 5a7c04937d53637d16ee3df14597bcd0f929aa2f Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Marc-Antoine=20Dupr=C3=A9?= Date: Mon, 10 Jun 2024 12:47:59 +0200 Subject: [PATCH] =?UTF-8?q?=F0=9F=90=9B=20[BUG]=20Apidae=20Trek=20parser?= =?UTF-8?q?=20now=20ignores=20when=20no=20linestring=20in=20GPX?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Previously caused a crash. --- docs/changelog.rst | 1 + geotrek/trekking/parsers.py | 2 ++ .../tests/data/apidae_trek_parser/trace_with_no_feature.gpx | 5 +++++ geotrek/trekking/tests/test_parsers.py | 6 ++++++ 4 files changed, 14 insertions(+) create mode 100644 geotrek/trekking/tests/data/apidae_trek_parser/trace_with_no_feature.gpx diff --git a/docs/changelog.rst b/docs/changelog.rst index 0de84fc94a..e761ef47dc 100644 --- a/docs/changelog.rst +++ b/docs/changelog.rst @@ -13,6 +13,7 @@ CHANGELOG **Bug fixes** - ApidaeTrekParser now fallbacks on trace filename extension if no extension property +- Apidae Trek parser now ignores when no linestring in GPX 2.109.1 (2024-08-22) diff --git a/geotrek/trekking/parsers.py b/geotrek/trekking/parsers.py index e9b8b55a6d..7c16c201c9 100644 --- a/geotrek/trekking/parsers.py +++ b/geotrek/trekking/parsers.py @@ -939,6 +939,8 @@ def _get_geom_from_gpx(data): geos = ApidaeTrekParser._maybe_get_linestring_from_layer(layer) if geos: break + else: + raise RowImportError("No LineString feature found in GPX layers tracks or routes") geos.transform(settings.SRID) return geos diff --git a/geotrek/trekking/tests/data/apidae_trek_parser/trace_with_no_feature.gpx b/geotrek/trekking/tests/data/apidae_trek_parser/trace_with_no_feature.gpx new file mode 100644 index 0000000000..688a805168 --- /dev/null +++ b/geotrek/trekking/tests/data/apidae_trek_parser/trace_with_no_feature.gpx @@ -0,0 +1,5 @@ + + + diff --git a/geotrek/trekking/tests/test_parsers.py b/geotrek/trekking/tests/test_parsers.py index 437681522f..a85f8c082f 100644 --- a/geotrek/trekking/tests/test_parsers.py +++ b/geotrek/trekking/tests/test_parsers.py @@ -1491,6 +1491,12 @@ def test_it_handles_segment_with_single_point(self): self.assertEqual(geom.geom_type, 'LineString') self.assertEqual(len(geom.coords), 13) + def test_it_raises_an_error_when_no_linestring(self): + gpx = self._get_gpx_from('geotrek/trekking/tests/data/apidae_trek_parser/trace_with_no_feature.gpx') + + with self.assertRaises(RowImportError): + ApidaeTrekParser._get_geom_from_gpx(gpx) + class KmlToGeomTests(SimpleTestCase):