diff --git a/Dockerfile b/Dockerfile index 01d9911dbe..1987602164 100644 --- a/Dockerfile +++ b/Dockerfile @@ -39,6 +39,13 @@ COPY ./requirements /app/requirements ARG TARGET_ENVIRONMENT=production RUN pip install -r requirements/${TARGET_ENVIRONMENT}.txt +# Apply patches of third party libraries +COPY ./patches /tmp/patches +RUN apt-get update && apt-get install -y --no-install-recommends \ + git \ + && rm -rf /var/lib/apt/lists/* \ + && /tmp/patches/apply.sh /usr/local/lib/python3.10/site-packages + # Stage 2 - Install frontend deps and build assets FROM node:16-bookworm-slim AS frontend-build diff --git a/patches/README.md b/patches/README.md new file mode 100644 index 0000000000..409cb84937 --- /dev/null +++ b/patches/README.md @@ -0,0 +1,11 @@ +# Patches + +This directory contains patches for third party code that has not been or won't ever be applied, but +are required for Open Forms to properly function. They are included in the docker image through the +`Dockerfile` instructions. + +## Django-yubin + +The Yubin patches are for the following PR: + +- https://github.com/APSL/django-yubin/pull/73 diff --git a/patches/apply.sh b/patches/apply.sh new file mode 100755 index 0000000000..84e1c56848 --- /dev/null +++ b/patches/apply.sh @@ -0,0 +1,22 @@ +#!/bin/bash + +set -eu -o pipefail + +SCRIPT_DIR=$( cd -- "$( dirname -- "${BASH_SOURCE[0]}" )" &> /dev/null && pwd ) + +sitepackagesdir=${1:-} +if [[ -z "$sitepackagesdir" ]]; then + echo "You must provide the path to site-packages"; + exit 1; +fi + +cd $sitepackagesdir +echo "Patching packages in: $(pwd)" + +for patch_file in $SCRIPT_DIR/yubin_00{1..1}.patch +do + echo "Applying patch file: $patch_file" + git apply $patch_file +done + +echo "Done patching." diff --git a/patches/yubin_001.patch b/patches/yubin_001.patch new file mode 100644 index 0000000000..a2dc05ff3b --- /dev/null +++ b/patches/yubin_001.patch @@ -0,0 +1,39 @@ +From 90ed636b1b1c7d3028c428e9e48a85683e619903 Mon Sep 17 00:00:00 2001 +From: Viicos <65306057+Viicos@users.noreply.github.com> +Date: Wed, 8 Nov 2023 11:30:38 +0100 +Subject: [PATCH] Call Celery task with `transaction.on_commit` + +--- + django_yubin/models.py | 5 +++-- + 1 file changed, 3 insertions(+), 2 deletions(-) + +diff --git a/django_yubin/models.py b/django_yubin/models.py +index 7a1e9db..352c5e3 100644 +--- a/django_yubin/models.py ++++ b/django_yubin/models.py +@@ -4,6 +4,7 @@ + from email import policy + from email import encoders as Encoders + from email.mime.base import MIMEBase ++from functools import partial + + from django.core.exceptions import FieldError + from django.core.mail.message import ( +@@ -11,7 +12,7 @@ + EmailMessage, + EmailMultiAlternatives, + ) +-from django.db import models ++from django.db import models, transaction + from django.db.models import F + from django.utils.module_loading import import_string + from django.utils.text import Truncator +@@ -254,7 +255,7 @@ def enqueue(self, log_message=None): + self.mark_as(self.STATUS_QUEUED, log_message) + + try: +- tasks.send_email.delay(self.pk) ++ transaction.on_commit(partial(tasks.send_email.delay, message_pk=self.pk)) + return True + except Exception as e: + self.date_enqueued = backup['date_enqueued']