Skip to content

Commit

Permalink
🦺 [#4057] Do not validate business logic during registration
Browse files Browse the repository at this point in the history
Discussed with the team on Slack, extensive input validation
where relations between configuration aspects are verified
for consistency and integrity is required, but only during
configuration of the form.

At registration time itself, only the validations that don't
touch external services are performed, so that:

* tests are simpler to write without having to set up mocks
  or VCR, distracting from the actual tested behaviour
* performance during registration is not affected because
  of additional IO. A validation error on this aspect
  would manifest as a runtime error anyway, which is the
  same outcome as the remote API not accepting the
  configured options.
  • Loading branch information
sergei-maertens committed Mar 27, 2024
1 parent 6ed79a6 commit 17ea68d
Show file tree
Hide file tree
Showing 2 changed files with 23 additions and 18 deletions.
33 changes: 17 additions & 16 deletions src/openforms/registrations/contrib/zgw_apis/options.py
Original file line number Diff line number Diff line change
Expand Up @@ -123,6 +123,10 @@ def validate(self, attrs: dict[str, Any]) -> dict[str, Any]:
# We know it exists thanks to the previous check
group_config = ZGWRegistration.get_zgw_config(attrs)

validate_business_logic = self.context.get("validate_business_logic", True)
if not validate_business_logic:
return attrs

# Run all validations against catalogi API in the same connection pool.
with get_catalogi_client(group_config) as client:
catalogi = client.get_all_catalogi()
Expand Down Expand Up @@ -183,22 +187,19 @@ def validate(self, attrs: dict[str, Any]) -> dict[str, Any]:
{"property_mappings": errors}, code="invalid"
)

if not ("medewerker_roltype" in attrs):
return attrs

roltypen = client.list_roltypen(
zaaktype=attrs["zaaktype"],
matcher=omschrijving_matcher(attrs["medewerker_roltype"]),
)

if not roltypen:
raise serializers.ValidationError(
{
"medewerker_roltype": _(
"Could not find a roltype with this description related to the zaaktype."
if "medewerker_roltype" in attrs:
roltypen = client.list_roltypen(
zaaktype=attrs["zaaktype"],
matcher=omschrijving_matcher(attrs["medewerker_roltype"]),
)
if not roltypen:
raise serializers.ValidationError(
{
"medewerker_roltype": _(
"Could not find a roltype with this description related to the zaaktype."
)
},
code="invalid",
)
},
code="invalid",
)

return attrs
8 changes: 6 additions & 2 deletions src/openforms/registrations/tasks.py
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,8 @@ def pre_registration(submission_id: int, event: PostSubmissionEvents) -> None:
return

options_serializer = registration_plugin.configuration_options(
data=submission.registration_backend.options
data=submission.registration_backend.options,
context={"validate_business_logic": False},
)

try:
Expand Down Expand Up @@ -229,7 +230,10 @@ def register_submission(submission_id: int, event: PostSubmissionEvents | str) -
return

logger.debug("De-serializing the plugin configuration options")
options_serializer = plugin.configuration_options(data=backend_config.options)
options_serializer = plugin.configuration_options(
data=backend_config.options,
context={"validate_business_logic": False},
)

try:
options_serializer.is_valid(raise_exception=True)
Expand Down

0 comments on commit 17ea68d

Please sign in to comment.