diff --git a/swh/loader/package/debian/loader.py b/swh/loader/package/debian/loader.py --- a/swh/loader/package/debian/loader.py +++ b/swh/loader/package/debian/loader.py @@ -89,31 +89,38 @@ yield release_name(version), p_info def resolve_revision_from( - self, known_package_artifacts: Dict, artifact_metadata: Dict) \ + self, known_package_artifacts: Mapping, + artifact_metadata: Mapping[str, Any]) \ -> Optional[bytes]: - artifacts_to_fetch = artifact_metadata['files'] - logger.debug('k_p_artifacts: %s', known_package_artifacts) - logger.debug('artifacts_to_fetch: %s', artifacts_to_fetch) - for rev_id, known_artifacts in known_package_artifacts.items(): - logger.debug('Revision: %s', rev_id) - logger.debug('Associated known_artifacts: %s', known_artifacts) - known_artifacts = known_artifacts['extrinsic']['raw']['files'] - rev_found = True - for a_name, k_artifact in known_artifacts.items(): - artifact_to_fetch = artifacts_to_fetch.get(a_name) - logger.debug('artifact_to_fetch: %s', artifact_to_fetch) - if artifact_to_fetch is None: - # as soon as we do not see an artifact, we consider we need - # to check the other revision - rev_found = False - if k_artifact['sha256'] != artifact_to_fetch['sha256']: - # Hash is different, we consider we need to check the other - # revisions - rev_found = False - if rev_found: - logger.debug('Existing revision %s found for new artifacts.', - rev_id) - return rev_id + try: + artifacts_to_fetch = artifact_metadata['files'] + logger.debug('k_p_artifacts: %s', known_package_artifacts) + logger.debug('artifacts_to_fetch: %s', artifacts_to_fetch) + for rev_id, known_artifacts in known_package_artifacts.items(): + logger.debug('Revision: %s', rev_id) + logger.debug('Associated known_artifacts: %s', known_artifacts) + known_artifacts = known_artifacts['extrinsic']['raw']['files'] + rev_found = False + for a_name, k_artifact in known_artifacts.items(): + artifact_to_fetch = artifacts_to_fetch.get(a_name) + logger.debug('artifact_to_fetch: %s', artifact_to_fetch) + if artifact_to_fetch is None: + # as soon as we do not see an artifact, we consider we + # need to check the other revision + continue + if k_artifact['sha256'] == artifact_to_fetch['sha256']: + # Hash is different, we consider we need to check the + # other revisions + rev_found = True + break + if rev_found: + logger.debug( + 'Existing revision %s found for new artifacts.', + rev_id) + return rev_id + except KeyError as e: + logger.warning( + 'Older revision format detected. Reason: Missing key %s', e) logger.debug('No existing revision found for the new artifacts.') return None