diff --git a/swh/lister/maven/lister.py b/swh/lister/maven/lister.py --- a/swh/lister/maven/lister.py +++ b/swh/lister/maven/lister.py @@ -304,11 +304,11 @@ # Origin is gathering source archives: last_update_dt = None last_update_iso = "" - last_update_seconds = str(page["time"])[:-3] try: + last_update_seconds = str(page["time"])[:-3] last_update_dt = datetime.fromtimestamp(int(last_update_seconds)) last_update_dt = last_update_dt.astimezone(timezone.utc) - except OverflowError: + except (OverflowError, ValueError): logger.warning("- Failed to convert datetime %s.", last_update_seconds) if last_update_dt: last_update_iso = last_update_dt.isoformat() diff --git a/swh/lister/maven/tests/data/http_indexes/export_null_mtime.fld b/swh/lister/maven/tests/data/http_indexes/export_null_mtime.fld new file mode 100644 --- /dev/null +++ b/swh/lister/maven/tests/data/http_indexes/export_null_mtime.fld @@ -0,0 +1,21 @@ +doc 0 + field 0 + name u + type string + value al.aldi|sprova4j|0.1.0|sources|jar + field 1 + name m + type string + value 1633786348254 + field 2 + name i + type string + value jar|0|14316|2|2|0|jar + field 10 + name n + type string + value sprova4j + field 11 + name d + type string + value Java client for Sprova Test Management diff --git a/swh/lister/maven/tests/test_lister.py b/swh/lister/maven/tests/test_lister.py --- a/swh/lister/maven/tests/test_lister.py +++ b/swh/lister/maven/tests/test_lister.py @@ -66,6 +66,11 @@ return Path(datadir, "https_maven.org", "sprova4j-0.1.0.pom").read_text() +@pytest.fixture +def maven_index_null_mtime(datadir) -> str: + return Path(datadir, "http_indexes", "export_null_mtime.fld").read_text() + + @pytest.fixture def maven_pom_1_malformed(datadir) -> str: return Path(datadir, "https_maven.org", "sprova4j-0.1.0.malformed.pom").read_text() @@ -290,3 +295,25 @@ # then we get only one maven-jar origin and one git origin. scheduler_origins = swh_scheduler.get_listed_origins(lister.lister_obj.id).results assert len(scheduler_origins) == 3 + + +def test_maven_lister_null_mtime(swh_scheduler, requests_mock, maven_index_null_mtime): + + requests_mock.get(INDEX_URL, text=maven_index_null_mtime) + + # Run the lister. + lister = MavenLister( + scheduler=swh_scheduler, + url=MVN_URL, + instance="maven.org", + index_url=INDEX_URL, + incremental=False, + ) + + stats = lister.run() + + # Start test checks. + assert stats.pages == 1 + scheduler_origins = swh_scheduler.get_listed_origins(lister.lister_obj.id).results + assert len(scheduler_origins) == 1 + assert scheduler_origins[0].last_update is None