-
Notifications
You must be signed in to change notification settings - Fork 26
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
💥 [#3283] Make objects/objecttypes FKs non-nullable in Objects API group
Catalogi and Documents API are optional, but the objecttypes and objects API services are not. These fields were null because the model was originally a django-solo singleton model which must be able to be created without any services existing prior. A check script is added to prevent being stuck in half-migrated upgrades.
- Loading branch information
1 parent
3a70208
commit 0b4513f
Showing
13 changed files
with
133 additions
and
110 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,56 @@ | ||
#!/usr/bin/env python | ||
import sys | ||
from pathlib import Path | ||
|
||
import django | ||
|
||
from tabulate import tabulate | ||
|
||
SRC_DIR = Path(__file__).parent.parent / "src" | ||
sys.path.insert(0, str(SRC_DIR.resolve())) | ||
|
||
|
||
def check_for_null_services_in_api_groups(): | ||
from openforms.contrib.objects_api.models import ObjectsAPIGroupConfig | ||
|
||
problems: list[tuple[str, int, str, str]] = [] | ||
|
||
objects_groups = ObjectsAPIGroupConfig.objects.exclude( | ||
objects_service__isnull=False, objecttypes_service__isnull=False | ||
).values_list("id", "name", "objects_service_id", "objecttypes_service_id") | ||
|
||
for pk, name, objects_service_id, objecttypes_service_id in objects_groups: | ||
problem = ("Objects API", pk, name) | ||
if objects_service_id is None: | ||
problems.append((*problem, "No objects service configured")) | ||
if objecttypes_service_id is None: | ||
problems.append((*problem, "No object types service configured")) | ||
|
||
if not problems: | ||
return False | ||
|
||
print( | ||
"Can't upgrade yet - some API group services are not properly configured yet." | ||
) | ||
print( | ||
"Go into the admin to fix their configuration, and then try to upgrade again." | ||
) | ||
tabulate( | ||
problems, | ||
headers=("API group type", "ID", "Name", "Problem"), | ||
) | ||
return True | ||
|
||
|
||
def main(skip_setup=False) -> bool: | ||
from openforms.setup import setup_env | ||
|
||
if not skip_setup: | ||
setup_env() | ||
django.setup() | ||
|
||
return check_for_null_services_in_api_groups() | ||
|
||
|
||
if __name__ == "__main__": | ||
main() |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
37 changes: 37 additions & 0 deletions
37
...ntrib/objects_api/migrations/0004_alter_objectsapigroupconfig_objects_service_and_more.py
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,37 @@ | ||
# Generated by Django 4.2.17 on 2024-12-12 22:40 | ||
|
||
import django.db.models.deletion | ||
from django.db import migrations, models | ||
|
||
|
||
class Migration(migrations.Migration): | ||
|
||
dependencies = [ | ||
("zgw_consumers", "0022_set_default_service_slug"), | ||
("objects_api", "0003_objectsapigroupconfig_identifier_unique"), | ||
] | ||
|
||
operations = [ | ||
migrations.AlterField( | ||
model_name="objectsapigroupconfig", | ||
name="objects_service", | ||
field=models.ForeignKey( | ||
limit_choices_to={"api_type": "orc"}, | ||
on_delete=django.db.models.deletion.PROTECT, | ||
related_name="+", | ||
to="zgw_consumers.service", | ||
verbose_name="Objects API", | ||
), | ||
), | ||
migrations.AlterField( | ||
model_name="objectsapigroupconfig", | ||
name="objecttypes_service", | ||
field=models.ForeignKey( | ||
limit_choices_to={"api_type": "orc"}, | ||
on_delete=django.db.models.deletion.PROTECT, | ||
related_name="+", | ||
to="zgw_consumers.service", | ||
verbose_name="Objecttypes API", | ||
), | ||
), | ||
] |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.