Skip to content

Commit

Permalink
Merge pull request #3583 from open-formulieren/issue/backport-yubin-r…
Browse files Browse the repository at this point in the history
…ace-patch

Backport yubin patch
  • Loading branch information
sergei-maertens authored Nov 8, 2023
2 parents 59b1de5 + 6ac63fc commit 76a0db8
Show file tree
Hide file tree
Showing 4 changed files with 79 additions and 0 deletions.
7 changes: 7 additions & 0 deletions Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down
11 changes: 11 additions & 0 deletions patches/README.md
Original file line number Diff line number Diff line change
@@ -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
22 changes: 22 additions & 0 deletions patches/apply.sh
Original file line number Diff line number Diff line change
@@ -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."
39 changes: 39 additions & 0 deletions patches/yubin_001.patch
Original file line number Diff line number Diff line change
@@ -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']

0 comments on commit 76a0db8

Please sign in to comment.