Skip to content

Commit

Permalink
fix: properly interpret Optional[] in seqvars types and API (#1789) (#…
Browse files Browse the repository at this point in the history
  • Loading branch information
holtgrewe authored Jul 12, 2024
1 parent 69bae65 commit 36da785
Show file tree
Hide file tree
Showing 7 changed files with 124 additions and 61 deletions.
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
# Generated by Django 3.2.25 on 2024-07-12 04:39

from django.db import migrations, models
import django.db.models.deletion


class Migration(migrations.Migration):

dependencies = [
("seqvars", "0002_auto_20240708_1305"),
]

operations = [
migrations.AddField(
model_name="seqvarsquerysettings",
name="predefinedquery",
field=models.ForeignKey(
blank=True,
null=True,
on_delete=django.db.models.deletion.PROTECT,
to="seqvars.seqvarspredefinedquery",
),
),
]
8 changes: 6 additions & 2 deletions backend/seqvars/models.py
Original file line number Diff line number Diff line change
Expand Up @@ -522,7 +522,6 @@ def clone_with_presetsset(
status=self.STATUS_DRAFT,
)

old_uuid_to_new_obj = {}
for key in (
"seqvarsquerypresetsfrequency_set",
"seqvarsquerypresetsvariantprio_set",
Expand Down Expand Up @@ -722,11 +721,16 @@ class SeqvarsQuerySettings(BaseModel):
#: The presets set version that this ``QuerySettings`` is based on.
#:
#: This information is used for computing differences between the presets and the
#: effective query settings.
#: effective query settings (together with ``predefinedquery``).
presetssetversion = models.ForeignKey(
SeqvarsQueryPresetsSetVersion, on_delete=models.PROTECT, null=True, blank=True
)

#: The predefined query that this ``QuerySettings`` is based on.
predefinedquery = models.ForeignKey(
SeqvarsPredefinedQuery, on_delete=models.PROTECT, null=True, blank=True
)

def __str__(self):
return f"SeqvarsQuerySettings '{self.sodar_uuid}'"

Expand Down
3 changes: 3 additions & 0 deletions backend/seqvars/serializers.py
Original file line number Diff line number Diff line change
Expand Up @@ -769,6 +769,8 @@ class SeqvarsQuerySettingsSerializer(BaseModelSerializer):

#: Serialize ``presetssetversion`` as its ``sodar_uuid``.
presetssetversion = serializers.ReadOnlyField(source="presetssetversion.sodar_uuid")
#: Serialize ``predefinedquery`` as its ``sodar_uuid``.
predefinedquery = serializers.ReadOnlyField(source="predefinedquery.sodar_uuid")

#: Serialize ``genotype`` as its ``sodar_uuid``.
genotype = serializers.ReadOnlyField(source="genotype.sodar_uuid")
Expand Down Expand Up @@ -798,6 +800,7 @@ class Meta:
fields = BaseModelSerializer.Meta.fields + [
"session",
"presetssetversion",
"predefinedquery",
"genotype",
"quality",
"consequence",
Expand Down
6 changes: 3 additions & 3 deletions backend/varfish/spectacular_utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,15 +11,15 @@

def pydantic_to_json_schema(schema_arg: typing.Any) -> typing.Dict[str, typing.Any]:
"""Convert a Python/pydantic schema to a JSON schema."""
if type(schema_arg) is type(int) or type(schema_arg) is type(float):
if schema_arg is int or schema_arg is float:
return {
"type": "number",
}
elif type(schema_arg) is type(str):
elif schema_arg is str:
return {
"type": "string",
}
elif type(schema_arg) is type(None):
elif schema_arg is type(None):
return {
"type": "null",
}
Expand Down
50 changes: 32 additions & 18 deletions backend/varfish/tests/drf_openapi_schema/varfish_api_schema.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -6951,7 +6951,7 @@ components:
default: null
title: SeqvarsGenotypePresets
type: object
- type: number
- type: 'null'
default:
choice: null
quality:
Expand Down Expand Up @@ -7176,7 +7176,7 @@ components:
title: Frequency
title: GnomadNuclearFrequencySettings
type: object
- type: number
- type: 'null'
gnomad_genomes:
oneOf:
- description: Settings for gnomAD nuclear frequency filtering.
Expand Down Expand Up @@ -7211,7 +7211,7 @@ components:
title: Frequency
title: GnomadNuclearFrequencySettings
type: object
- type: number
- type: 'null'
gnomad_mitochondrial:
oneOf:
- description: Settings for gnomAD mitochondrial frequency filtering.
Expand Down Expand Up @@ -7240,7 +7240,7 @@ components:
title: Frequency
title: GnomadMitochondrialFrequencySettings
type: object
- type: number
- type: 'null'
helixmtdb:
oneOf:
- description: Settings for HelixMtDb frequency filtering.
Expand Down Expand Up @@ -7269,7 +7269,7 @@ components:
title: Frequency
title: HelixmtDbFrequencySettings
type: object
- type: number
- type: 'null'
inhouse:
oneOf:
- description: Settings for in-house frequency filtering.
Expand Down Expand Up @@ -7304,7 +7304,7 @@ components:
title: Carriers
title: InhouseFrequencySettings
type: object
- type: number
- type: 'null'
sodar_uuid:
type: string
format: uuid
Expand Down Expand Up @@ -7591,6 +7591,10 @@ components:
type: string
format: uuid
readOnly: true
predefinedquery:
type: string
format: uuid
readOnly: true
genotype:
$ref: '#/components/schemas/SeqvarsQuerySettingsGenotype'
quality:
Expand Down Expand Up @@ -8527,7 +8531,7 @@ components:
default: null
title: SeqvarsGenotypePresets
type: object
- type: number
- type: 'null'
default:
choice: null
quality:
Expand Down Expand Up @@ -8994,7 +8998,7 @@ components:
title: Frequency
title: GnomadNuclearFrequencySettings
type: object
- type: number
- type: 'null'
gnomad_genomes:
oneOf:
- description: Settings for gnomAD nuclear frequency filtering.
Expand Down Expand Up @@ -9029,7 +9033,7 @@ components:
title: Frequency
title: GnomadNuclearFrequencySettings
type: object
- type: number
- type: 'null'
gnomad_mitochondrial:
oneOf:
- description: Settings for gnomAD mitochondrial frequency filtering.
Expand Down Expand Up @@ -9058,7 +9062,7 @@ components:
title: Frequency
title: GnomadMitochondrialFrequencySettings
type: object
- type: number
- type: 'null'
helixmtdb:
oneOf:
- description: Settings for HelixMtDb frequency filtering.
Expand Down Expand Up @@ -9087,7 +9091,7 @@ components:
title: Frequency
title: HelixmtDbFrequencySettings
type: object
- type: number
- type: 'null'
inhouse:
oneOf:
- description: Settings for in-house frequency filtering.
Expand Down Expand Up @@ -9122,7 +9126,7 @@ components:
title: Carriers
title: InhouseFrequencySettings
type: object
- type: number
- type: 'null'
sodar_uuid:
type: string
format: uuid
Expand Down Expand Up @@ -9586,6 +9590,10 @@ components:
type: string
format: uuid
readOnly: true
predefinedquery:
type: string
format: uuid
readOnly: true
genotype:
type: string
format: uuid
Expand Down Expand Up @@ -9627,6 +9635,7 @@ components:
- genotype
- locus
- phenotypeprio
- predefinedquery
- presetssetversion
- quality
- session
Expand Down Expand Up @@ -9727,6 +9736,10 @@ components:
type: string
format: uuid
readOnly: true
predefinedquery:
type: string
format: uuid
readOnly: true
genotype:
$ref: '#/components/schemas/SeqvarsQuerySettingsGenotype'
quality:
Expand All @@ -9752,6 +9765,7 @@ components:
- genotype
- locus
- phenotypeprio
- predefinedquery
- presetssetversion
- quality
- session
Expand Down Expand Up @@ -9795,7 +9809,7 @@ components:
title: Frequency
title: GnomadNuclearFrequencySettings
type: object
- type: number
- type: 'null'
gnomad_genomes:
oneOf:
- description: Settings for gnomAD nuclear frequency filtering.
Expand Down Expand Up @@ -9830,7 +9844,7 @@ components:
title: Frequency
title: GnomadNuclearFrequencySettings
type: object
- type: number
- type: 'null'
gnomad_mitochondrial:
oneOf:
- description: Settings for gnomAD mitochondrial frequency filtering.
Expand Down Expand Up @@ -9859,7 +9873,7 @@ components:
title: Frequency
title: GnomadMitochondrialFrequencySettings
type: object
- type: number
- type: 'null'
helixmtdb:
oneOf:
- description: Settings for HelixMtDb frequency filtering.
Expand Down Expand Up @@ -9888,7 +9902,7 @@ components:
title: Frequency
title: HelixmtDbFrequencySettings
type: object
- type: number
- type: 'null'
inhouse:
oneOf:
- description: Settings for in-house frequency filtering.
Expand Down Expand Up @@ -9923,7 +9937,7 @@ components:
title: Carriers
title: InhouseFrequencySettings
type: object
- type: number
- type: 'null'
sodar_uuid:
type: string
format: uuid
Expand Down Expand Up @@ -10427,7 +10441,7 @@ components:
strList:
type: array
items:
type: number
type: string
securitySchemes:
basicAuth:
type: http
Expand Down
Loading

0 comments on commit 36da785

Please sign in to comment.