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. @@ -142,6 +145,9 @@ Either swhid or origin reference if any. None otherwise. """ # noqa + visit_swhid = None + anchor_swhid = None + swh_deposit = metadata.get("swh:deposit") if not swh_deposit: return None @@ -184,4 +190,18 @@ 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}" + ) + raise ValidationError( + "'anchor=swh:1:snp:' is not supported when 'visit' is also provided." + ) + 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 @@ -224,7 +224,11 @@ ( "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 + "anchor=swh:1:snp", + ), ], ) def test_parse_swh_reference_invalid_swhid(invalid_swhid, error_msg, xml_with_swhid):