Skip to content

Commit

Permalink
💥 [#3283] Remove conversion of form step URL to form step UUID
Browse files Browse the repository at this point in the history
Fully qualified URLs to resolve a form step have been deprecated for
a while, since they're not portable across environments with different
base URLs.

Now the compatibility code is removed too, which may break old exports.
  • Loading branch information
sergei-maertens committed Dec 9, 2024
1 parent ae74347 commit 61dfe27
Show file tree
Hide file tree
Showing 4 changed files with 22 additions and 36 deletions.
7 changes: 7 additions & 0 deletions docs/installation/upgrade-300.rst
Original file line number Diff line number Diff line change
Expand Up @@ -91,6 +91,13 @@ active locale field (``name_nl`` or ``name_en``) during imports. Instead, the
``translations`` key existed. We recommend re-creating the exports on a newer version
of Open Forms.

Removal of ``formStep`` reference in form logic
-----------------------------------------------

The ``formStep`` key was deprecated in favour of ``formStepUuid`` and the conversion
code has been removed. This may affect form exports from before Open Forms 2.1.0. We
recommend re-creating the exports on a newer version of Open Forms.

Removal of /api/v2/location/get-street-name-and-city endpoint
=============================================================

Expand Down
2 changes: 2 additions & 0 deletions pyright.pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,8 @@ include = [
# Formio tooling
"src/openforms/formio/typing/",
"src/openforms/formio/formatters/",
# Core forms app
"src/openforms/forms/api/serializers/logic/action_serializers.py",
# Payments
"src/openforms/payments/models.py",
# Interaction with the outside world
Expand Down
46 changes: 12 additions & 34 deletions src/openforms/forms/api/serializers/logic/action_serializers.py
Original file line number Diff line number Diff line change
@@ -1,12 +1,9 @@
import warnings
from datetime import date

from django.urls import resolve
from django.utils.translation import gettext_lazy as _

from drf_polymorphic.serializers import PolymorphicSerializer
from drf_spectacular.utils import extend_schema_serializer
from furl import furl
from json_logic.typing import Primitive
from rest_framework import serializers

Expand Down Expand Up @@ -168,18 +165,6 @@ class LogicComponentActionSerializer(serializers.Serializer):
)
),
)
# Deprecated field! form_step_uuid should be used instead
form_step = serializers.URLField(
allow_null=True,
required=False, # validated against the action.type
allow_blank=True,
label=_("form step"),
help_text=_(
"The form step that will be affected by the action. This field is "
"required if the action type is `%(action_type)s`, otherwise optional."
)
% {"action_type": LogicActionTypes.step_not_applicable},
)
form_step_uuid = ActionFormStepUUIDField(
allow_null=True,
required=False, # validated against the action.type
Expand All @@ -192,27 +177,17 @@ class LogicComponentActionSerializer(serializers.Serializer):
)
action = LogicActionPolymorphicSerializer()

def validate(self, data: dict) -> dict:
def validate(self, attrs: dict) -> dict:
"""
1. Check that the component is supplied depending on the action type.
2. Check that the value for date variables has the right format
"""
action_type = data.get("action", {}).get("type")
action_value = data.get("action", {}).get("value")
component = data.get("component")
form_step = data.get("form_step")

if form_step and not data.get("form_step_uuid"):
warnings.warn(
"Logic action 'formStep' is deprecated, use 'formStepUuid' instead",
DeprecationWarning,
)
# normalize to UUID following deprecation of URL reference
match = resolve(furl(form_step).path)
data["form_step_uuid"] = match.kwargs["uuid"]
action_type = attrs.get("action", {}).get("type")
action_value = attrs.get("action", {}).get("value")
component = attrs.get("component")

form_step_uuid = data.get("form_step_uuid")
variable = data.get("variable")
form_step_uuid = attrs.get("form_step_uuid")
variable = attrs.get("variable")

if (
action_type
Expand Down Expand Up @@ -254,7 +229,10 @@ def validate(self, data: dict) -> dict:

if form_var.data_type == FormVariableDataTypes.date:
try:
date.fromisoformat(action_value)
# type check muted since we handle it at runtime
date.fromisoformat(
action_value

Check failure on line 234 in src/openforms/forms/api/serializers/logic/action_serializers.py

View workflow job for this annotation

GitHub Actions / Type checking (Pyright)

Argument of type "str | int | float | bool | None" cannot be assigned to parameter "date_string" of type "str" in function "fromisoformat"   Type "str | int | float | bool | None" is incompatible with type "str"     "float" is incompatible with "str" (reportArgumentType)
) # pyright: ignore[reportArgumentType]
except (ValueError, TypeError) as ex:
raise serializers.ValidationError(
{
Expand All @@ -270,7 +248,7 @@ def validate(self, data: dict) -> dict:
if (
action_type
and action_type == LogicActionTypes.step_not_applicable
and (not form_step and not form_step_uuid)
and not form_step_uuid
):
raise serializers.ValidationError(
{
Expand All @@ -281,4 +259,4 @@ def validate(self, data: dict) -> dict:
code="blank",
)

return data
return attrs
3 changes: 1 addition & 2 deletions src/openforms/forms/tests/test_import_export.py
Original file line number Diff line number Diff line change
Expand Up @@ -873,8 +873,7 @@ def test_import_form_with_disable_step_logic(self):
"actions": [
{
"action": {"type": "step-not-applicable"},
# In versions <= 2.0, we used the url of the form step, but this was replaced with the UUID
"form_step": "http://127.0.0.1:8999/api/v2/forms/324cadce-a627-4e3f-b117-37ca232f16b2/steps/a54864c6-c460-48bd-a520-eced60ffb209",
"form_step_uuid": "a54864c6-c460-48bd-a520-eced60ffb209",
}
],
"form": "http://testserver/api/v2/forms/324cadce-a627-4e3f-b117-37ca232f16b2",
Expand Down

0 comments on commit 61dfe27

Please sign in to comment.