Auto detected bugs - upload
- Dominant language
- Python
- Stars
- 30
- Forks
- 3
- Avg merge
- 9h 28m
- Merged PRs (30d)
- 42
Description
# Upload App — Bug Report
## BUG 1: Checks the raw key instead of the looked-up value — condition is always False [MEDIUM]
**File:** `upload/vcf/vcf_import.py` ~line 80
```python
raw_data_type = request.GET.get("data_type")
data_type = DATA_TYPE_MAP.get(raw_data_type)
if raw_data_type is None: # BUG: should check data_type (the lookup result)
raise ValueError(...)
```
`raw_data_type` comes from `request.GET.get(...)` — if the key is missing, `raw_data_type` is `None` and the check fires correctly. But if the key is present with an *unrecognised* value (e.g., `?data_type=garbage`), `raw_data_type` is not `None`, so the guard is skipped, and `data_type` is silently `None` and used downstream. The check should test the *result* of the dictionary lookup.
**Fix:**
Dave Note: use walrus?
```python
if data_type is None:
raise ValueError(f"Unknown data_type: {raw_data_type!r}")
```
---
## BUG 2: Wrong exception class name — exception never caught, error handling silently skipped [HIGH]
**File:** `upload/views/views.py` ~line 103
```python
try:
vcf = uploaded_file.uploadedvcf
except UploadedVCF.RelatedObjectDoesNotExist: # BUG: wrong exception name
vcf = None
```
The correct exception for a missing reverse OneToOne relation is `UploadedVCF.DoesNotExist` (or `RelatedObjectDoesNotExist` raised from the *accessor*, not the model class). Using `UploadedVCF.RelatedObjectDoesNotExist` either raises `AttributeError` (no such attribute on the model class) or silently fails to catch the exception, letting it propagate uncaught.
**Fix:**
```python
try:
vcf = uploaded_file.uploadedvcf
except Exception: # or the correct RelatedObjectDoesNotExist from django.core.exceptions
vcf = None
```
More precisely:
```python
from django.core.exceptions import ObjectDoesNotExist
try:
vcf = uploaded_file.uploadedvcf
except ObjectDoesNotExist:
vcf = None
```
Contributor guide
No contributing guide indexed for this repository
Assessment
This issue has not been assessed yet.