Auto detected bugs - snpdb
- Dominant language
- Python
- Stars
- 30
- Forks
- 3
- Avg merge
- 9h 28m
- Merged PRs (30d)
- 42
Description
BUG 1 — TypeError: len() on Sequence model instead of Sequence.seq string
FILE: snpdb/models/models_variant.py
LINE: 677
IMPACT: HIGH — runtime TypeError whenever is_deletion is called on a
non-symbolic variant (the common case)
is_insertion (line 671) correctly does:
```
return self.alt.seq != Variant.REFERENCE_ALT and len(self.locus.ref.seq) < len(self.alt.seq)
```
But is_deletion on line 677 drops the .seq:
```
return self.alt.seq != Variant.REFERENCE_ALT and len(self.locus.ref) > len(self.alt.seq)
```
self.locus.ref is a ForeignKey to a Sequence model instance.
The Sequence model (line 439–453) defines no __len__, so calling len() on it
raises TypeError: object of type 'Sequence' has no len().
Fix: change `len(self.locus.ref)` → `len(self.locus.ref.seq)` to match line 671.
Dave comment - confirmed this is true:
```
In [8]: v = Variant.objects.filter(locus__ref__seq='GAG').first()
In [9]: v
Out[9]: C>
In [10]: v.is_deletion
Out[10]: False
```
--------------------------------------------------------------------------------
BUG 2 — TypeError: len() on Sequence model objects in _clingen_allele_size
FILE: snpdb/models/models_variant.py
LINE: 699
IMPACT: HIGH — runtime TypeError whenever can_have_clingen_allele is checked
on a non-symbolic variant
```
@property
def _clingen_allele_size(self) -> int:
if self.is_symbolic:
...
else:
allele_size = len(self.locus.ref) + len(self.alt) # BUG: both missing .seq
return allele_size
```
Both self.locus.ref and self.alt are Sequence model instances (not strings).
Neither has __len__. The property is used by can_have_clingen_allele (line 704),
so any attempt to check whether a regular variant can be submitted to ClinGen
will raise TypeError.
Fix: change to `len(self.locus.ref.seq) + len(self.alt.seq)`
--------------------------------------------------------------------------------
BUG 3 — Operator precedence: can_have_c_hgvs returns wrong values
FILE: snpdb/models/models_variant.py
LINE: 712
IMPACT: HIGH — can_have_c_hgvs returns True for variants that cannot have
c.HGVS (when can_have_annotation is False but svlen is in range),
and may raise TypeError when svlen is None and can_have_annotation
is False (abs(None) on the second or-branch)
```
def can_have_c_hgvs(self) -> bool:
return self.can_have_annotation and self.svlen is None or abs(self.svlen) <= settings.HGVS_MAX_SEQUENCE_LENGTH
```
Python evaluates `and` before `or`, so this parses as:
return (self.can_have_annotation and self.svlen is None) or (abs(self.svlen) <= settings.HGVS_MAX_SEQUENCE_LENGTH)
Problems:
a) If can_have_annotation=False and svlen=not None:
→ evaluates right branch: returns True even though annotation is not possible
b) If can_have_annotation=False and svlen=None:
→ evaluates right branch: abs(None) → TypeError
The intended logic is clearly:
return self.can_have_annotation and (self.svlen is None or abs(self.svlen) <= settings.HGVS_MAX_SEQUENCE_LENGTH)
Fix: add parentheses as shown above.
--------------------------------------------------------------------------------
BUG 4 — None appended to SQL __in list, causing unintended NULL matching
FILE: snpdb/models/models_cohort.py
LINE: 459
IMPACT: MEDIUM — when common_collection_id is None (no common partition),
the ORM query gains a spurious IS NULL condition, potentially
returning extra cohortgenotype rows that belong to no collection
```
def get_annotation_kwargs(self, **kwargs) -> dict:
collections = [self.pk]
if kwargs.get("common_variants", True):
collections.append(self.common_collection_id) # BUG: can be None
cgc_condition = Q(cohortgenotype__collection__in=collections)
```
common_collection is defined as OneToOneField('self', null=True, ...).
When no common partition exists, common_collection_id is None.
Django's ORM translates Q(field__in=[pk, None]) to:
WHERE collection_id IN (pk) OR collection_id IS NULL
The IS NULL arm can match cohortgenotype rows that belong to no collection,
corrupting the variant queryset with unintended rows.
Fix:
```
if kwargs.get("common_variants", True) and self.common_collection_id is not None:
collections.append(self.common_collection_id)
```
Contributor guide
No contributing guide indexed for this repository
Assessment
This issue has not been assessed yet.