Skip to content

Commit

Permalink
🐛 [#4908] Fix bugs with JSON serializing
Browse files Browse the repository at this point in the history
* The requests.Response object is not JSON serializable, so need to add just the json response (assuming it is json for now) of it .
* Convert the data to be sent to a json format. Needed because date/datetimes are not JSON serializable
  • Loading branch information
viktorvanwijk committed Jan 21, 2025
1 parent 12f5d78 commit 55a4d25
Showing 1 changed file with 7 additions and 4 deletions.
11 changes: 7 additions & 4 deletions src/openforms/registrations/contrib/json_dump/plugin.py
Original file line number Diff line number Diff line change
@@ -1,12 +1,13 @@
import base64
import json

from django.core.serializers.json import DjangoJSONEncoder
from django.utils.translation import gettext_lazy as _

from zgw_consumers.client import build_client

from openforms.submissions.models import Submission
from openforms.typing import JSONObject
from openforms.variables.service import get_static_variables

from ...base import BasePlugin # openforms.registrations.base
from ...registry import register # openforms.registrations.registry
Expand Down Expand Up @@ -59,16 +60,18 @@ def register_submission(
}

# Send to the service
json = {"values": values, "schema": schema}
data = json.dumps({"values": values, "schema": schema}, cls=DjangoJSONEncoder)
service = options["service"]
submission.registration_result = result = {}
with build_client(service) as client:
result["api_response"] = res = client.post(
res = client.post(
options.get("relative_api_endpoint", ""),
json=json,
json=data,
)
res.raise_for_status()

result["api_response"] = res.json()

return result

def check_config(self) -> None:
Expand Down

0 comments on commit 55a4d25

Please sign in to comment.