Skip to content
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

[#2871] Refactor ZGW imports to work on different environments #1497

Merged
merged 2 commits into from
Nov 28, 2024

Conversation

pi-sigma
Copy link
Contributor

@pi-sigma pi-sigma commented Nov 14, 2024

  • Use composite natural key for CatalogusConfig and a combination of omschrijving + zaaktype_identificatie for nested ZGW objects like ZaakTypeStatusTypeConfig to support import/export of ZGW objects across different environments (where the url is different)
  • Update ZGW import/export logic to work with new natural keys
  • Update success and error messages displayed in the admin

Taiga: https://taiga.maykinmedia.nl/project/open-inwoner/task/2871

@pi-sigma pi-sigma force-pushed the task/2871-zgw-import-export branch 2 times, most recently from 1550dbd to 7bca41d Compare November 15, 2024 15:28
@pi-sigma pi-sigma changed the title [#2871] Use composite natural key (domein, rsin) for CatalogusConfig [#2871] Use composite natural key for ZGW entities Nov 15, 2024
@pi-sigma pi-sigma changed the title [#2871] Use composite natural key for ZGW entities [#2871] Refactor ZGW imports to work on different environments Nov 19, 2024
@pi-sigma pi-sigma force-pushed the task/2871-zgw-import-export branch 2 times, most recently from 3c6db4f to 5d89630 Compare November 22, 2024 14:51
…aints

    - use (domein, rsin) as natural key for CatalogusConfig
    - use combination of `omschrivjing` and (catalogus_domain, catalogus_rsin) for natural
      keys of nested ZGW configs (ZaakTypeConfig, ZaakTypeInformatieObjectTypeConfig etc.)
      and use (domein, rsin) support import/export of ZGW objects across different
      environments (where the url is different)
@codecov-commenter
Copy link

codecov-commenter commented Nov 25, 2024

Codecov Report

Attention: Patch coverage is 99.21569% with 2 lines in your changes missing coverage. Please review.

Project coverage is 94.30%. Comparing base (b534838) to head (24fffb7).
Report is 3 commits behind head on develop.

Files with missing lines Patch % Lines
src/open_inwoner/openzaak/import_export.py 97.89% 2 Missing ⚠️
Additional details and impacted files
@@            Coverage Diff            @@
##           develop    #1497    +/-   ##
=========================================
  Coverage    94.29%   94.30%            
=========================================
  Files         1066     1067     +1     
  Lines        40180    40295   +115     
=========================================
+ Hits         37889    38001   +112     
- Misses        2291     2294     +3     

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

@pi-sigma pi-sigma force-pushed the task/2871-zgw-import-export branch 2 times, most recently from e451213 to 2198320 Compare November 26, 2024 11:19
@pi-sigma pi-sigma marked this pull request as ready for review November 26, 2024 11:44
src/open_inwoner/openzaak/zgw_imports.py Outdated Show resolved Hide resolved
src/open_inwoner/openzaak/import_export.py Outdated Show resolved Hide resolved
src/open_inwoner/openzaak/import_export.py Outdated Show resolved Hide resolved
src/open_inwoner/openzaak/import_export.py Outdated Show resolved Hide resolved
src/open_inwoner/openzaak/import_export.py Outdated Show resolved Hide resolved
Comment on lines 101 to 121
def update_zaaktype_config(source_config: ZaakTypeConfig, jsonl: str):
try:
target = ZaakTypeConfig.objects.get_by_natural_key(
identificatie=source_config.identificatie,
catalogus_domein=source_config.catalogus.domein,
catalogus_rsin=source_config.catalogus.rsin,
)
except ZaakTypeConfig.MultipleObjectsReturned as exc:
raise ZGWImportError.from_exception_and_jsonl(exc, jsonl)
except (CatalogusConfig.DoesNotExist, ZaakTypeConfig.DoesNotExist) as exc:
raise ZGWImportError.from_exception_and_jsonl(exc, jsonl)
else:
exclude_fields = [
"id",
"catalogus",
]
for field in source_config._meta.fields:
field_name = field.name

if field_name in exclude_fields:
pass
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I generally feel there is a fair bit of duplication in these functions. I wonder whether we couldn't simply inline all of these functions in the match statement of the main loop, whereby each branch would define the target and the exclude fields, and then the loop would only do the updating logic once.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

(I guess the related object handling is slightly different, no worries if it's too much hassle, but it might make sense to mark the functions as private with the _ prefix).

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I moved the exclude_fields into the match statement, which makes the helper functions slimmer. I'm not sure more inlining would improve readability further, due to the difference between CatalogusConfig, ZaaktypeConfig, and the nested configs (the match statement would get pretty crowded).

src/open_inwoner/openzaak/admin.py Outdated Show resolved Hide resolved
src/open_inwoner/openzaak/admin.py Outdated Show resolved Hide resolved
src/open_inwoner/openzaak/import_export.py Outdated Show resolved Hide resolved
Copy link
Contributor

@swrichards swrichards left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Nice work, few suggestions here and there.

@pi-sigma pi-sigma force-pushed the task/2871-zgw-import-export branch 2 times, most recently from 15cecb9 to d1c148e Compare November 27, 2024 11:31
    - overwrite only editable fields when importing ZGW entities,
      skip read-only fields (url, domein, rsin)
@alextreme alextreme merged commit e589b3a into develop Nov 28, 2024
20 checks passed
@alextreme alextreme deleted the task/2871-zgw-import-export branch November 28, 2024 10:31
@alextreme alextreme restored the task/2871-zgw-import-export branch November 28, 2024 10:31
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants