Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Backport yubin patch #3583

Merged
merged 1 commit into from
Nov 8, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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 <[email protected]>
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']
Loading