-
Notifications
You must be signed in to change notification settings - Fork 26
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
💥 Make service FKs in API group config models not nullable #4916
Merged
sergei-maertens
merged 2 commits into
master
from
cleanup/3283-make-fields-not-nullable
Dec 17, 2024
Merged
Changes from all commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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,80 @@ | ||
#!/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 | ||
from openforms.registrations.contrib.zgw_apis.models import ZGWApiGroupConfig | ||
|
||
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")) | ||
|
||
zgw_groups = ZGWApiGroupConfig.objects.exclude( | ||
zrc_service__isnull=False, | ||
drc_service__isnull=False, | ||
ztc_service__isnull=False, | ||
).values_list( | ||
"id", | ||
"name", | ||
"zrc_service_id", | ||
"drc_service_id", | ||
"ztc_service_id", | ||
) | ||
for pk, name, zrc_service_id, drc_service_id, ztc_service_id in zgw_groups: | ||
problem = ("ZGW APIs", pk, name) | ||
if zrc_service_id is None: | ||
problems.append((*problem, "No Zaken API service configured")) | ||
if drc_service_id is None: | ||
problems.append((*problem, "No Documenten API service configured")) | ||
if ztc_service_id is None: | ||
problems.append((*problem, "No Catalogi API 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." | ||
) | ||
print( | ||
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
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Not a major thing, but does this have to return something?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
yeah, the return value is checked by the upgrade check which blocks migrating if problems are detected! See
open-forms/src/openforms/upgrades/upgrade_paths.py
Line 62 in 9be9f8c