Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 4 additions & 1 deletion annotation/import_task_factories.py
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,10 @@ def get_data_classes(self):
def get_processing_ability(self, user, filename, file_extension, **kwargs):
# cyvcf2 is what the pipeline reads with, and unlike PyVCF it tolerates the extra keys some callers
# put in FILTER lines (eg Illumina's Number=1,Type=String) - this runs for every uploaded VCF
reader = cyvcf2.VCF(filename)
try:
reader = cyvcf2.VCF(filename)
except Exception: # Every VCF factory is asked, so a file we can't read is someone else's
return 0
if cyvcf2_header_get(reader, "source") == "ClinVar":
check_can_import_clinvar(user)
return 2 # more specific than normal VCF
Expand Down
15 changes: 15 additions & 0 deletions upload/tests/test_api.py
Original file line number Diff line number Diff line change
Expand Up @@ -117,6 +117,21 @@ def test_empty_file_rejected(self):
self.assertIn("empty", response.json()["error"])
self.assertFalse(FileUpload.objects.filter(user=self.owner, name="empty.csv").exists())

def test_unreadable_vcf_is_accepted_as_a_vcf(self):
""" The ClinVar check reads every .vcf's header - one it can't read is left to the VCF import to fail,
reported through upload_status, rather than a 500 """
self.client.force_authenticate(user=self.owner)
with patch("upload.views.views_json.upload_processing.process_uploaded_file"):
response = self.client.post(
reverse("api_file_upload"),
{"file": SimpleUploadedFile("not_a_vcf.vcf", b"not a vcf\n")},
format="multipart",
)
self.assertEqual(response.status_code, status.HTTP_200_OK)
file_upload = FileUpload.objects.get(pk=response.json()["file_upload_id"])
self._temp_upload_paths.append(file_upload.get_filename())
self.assertEqual(file_upload.file_type, UploadedFileTypes.VCF)

def test_empty_file_rejected_web(self):
""" FilePond endpoint returns the message as text so the upload page can show it """
self.client.force_login(self.owner)
Expand Down
Loading