Skip to content

Commit

Permalink
glamr/checks: fix access field checks in case of DB errors
Browse files Browse the repository at this point in the history
Don't crash is DB os down or the migration adding the access field has
not been run yet.
  • Loading branch information
robert102 committed Nov 20, 2024
1 parent 34a57a7 commit c563d90
Showing 1 changed file with 22 additions and 2 deletions.
24 changes: 22 additions & 2 deletions mibios/glamr/managers.py
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,17 @@ def check_dataset_access(app_configs, **kwargs):
qs = Dataset.objects.only('access').prefetch_related('restricted_to')
good = []
bad = []
for obj in qs:

try:
qs_list = list(qs)
except Exception as e:
return [checks.Warning(
f'Unable to check Dataset.access consistency: {e}',
hint='apply all migrations, ensure you have a DB connection',
id='glamr.W011',
)]

for obj in qs_list:
groupids = sorted((i.pk for i in obj.restricted_to.all())) or [0]
if groupids == obj.access:
good.append(obj)
Expand Down Expand Up @@ -57,7 +67,17 @@ def check_sample_access(app_configs, **kwargs):
qs = qs.prefetch_related('dataset__restricted_to')
good = []
bad = []
for obj in qs:

try:
qs_list = list(qs)
except Exception as e:
return [checks.Warning(
f'Unable to check Sample.access consistency: {e}',
hint='apply all migrations, ensure you have a DB connection',
id='glamr.W012',
)]

for obj in qs_list:
groupids = sorted((i.pk for i in obj.dataset.restricted_to.all()))
if not groupids:
groupids = [0]
Expand Down

0 comments on commit c563d90

Please sign in to comment.