diff --git a/swh/deposit/parsers.py b/swh/deposit/parsers.py --- a/swh/deposit/parsers.py +++ b/swh/deposit/parsers.py @@ -8,6 +8,7 @@ """ +import logging from typing import Dict, Optional, Union from xml.parsers.expat import ExpatError @@ -26,6 +27,8 @@ parse_swhid, ) +logger = logging.getLogger(__name__) + class SWHFileUploadZipParser(FileUploadParser): """File upload parser limited to zip archive. @@ -184,4 +187,13 @@ f"visit qualifier should be a core SWHID with type {SNAPSHOT}" ) + if visit_swhid and anchor_swhid and visit_swhid.object_type == SNAPSHOT and \ + anchor_swhid.object_type == SNAPSHOT: + logger.warn("SWHID use of both anchor and visit targeting " + f"a snapshot: {swhid_reference}") + # FIXME: Find a real error message + raise ValidationError( + "Qualifiers anchor and visit targets both a SNAPSHOT, " + "please specify only visit." # or something? + return swhid_reference diff --git a/swh/deposit/tests/api/test_parsers.py b/swh/deposit/tests/api/test_parsers.py --- a/swh/deposit/tests/api/test_parsers.py +++ b/swh/deposit/tests/api/test_parsers.py @@ -225,6 +225,10 @@ "swh:1:rev:c4993c872593e960dc84e4430dbbfbc34fd706d0;anchor=swh:1:cnt:b5f505b005435fa5c4fa4c279792bd7b17167c04;path=/", # noqa "anchor qualifier should be a core SWHID with type one of", ), # noqa + ( + "swh:1:rev:c4993c872593e960dc84e4430dbbfbc34fd706d0;visit=swh:1:snp:0175049fc45055a3824a1675ac06e3711619a55a;anchor=swh:1:snp:b5f505b005435fa5c4fa4c279792bd7b17167c04", # noqa + "Qualifiers anchor and", + ), ], ) def test_parse_swh_reference_invalid_swhid(invalid_swhid, error_msg, xml_with_swhid):