From fc0b0839b106fda800ee592946c0f31321640a2e Mon Sep 17 00:00:00 2001
From: Teklia Bot <contact@teklia.com>
Date: Tue, 6 Dec 2022 14:28:11 +0000
Subject: [PATCH] Bump Python requirement Django to 4.1.4

---
 .gitlab-ci.yml                                      |  2 +-
 Dockerfile                                          |  4 ++--
 Dockerfile.binary                                   |  2 +-
 arkindex/documents/__init__.py                      |  1 -
 arkindex/images/serializers.py                      |  8 +++-----
 arkindex/process/__init__.py                        |  1 -
 arkindex/project/aws.py                             |  2 +-
 arkindex/project/settings.py                        | 13 +++++++++++--
 arkindex/project/tests/test_argparse.py             |  4 ++--
 arkindex/sql_validation/corpus_right_access.sql     |  2 +-
 .../sql_validation/element_move_with_children.sql   |  4 ++--
 .../sql_validation/element_move_without_child.sql   |  4 ++--
 .../sql_validation/process_elements_filter_type.sql |  2 +-
 .../sql_validation/process_elements_top_level.sql   |  2 +-
 .../sql_validation/process_elements_with_image.sql  |  2 +-
 arkindex/users/__init__.py                          |  1 -
 base/requirements.txt                               |  2 +-
 17 files changed, 30 insertions(+), 26 deletions(-)

diff --git a/.gitlab-ci.yml b/.gitlab-ci.yml
index 51bdc21217..3a88df443d 100644
--- a/.gitlab-ci.yml
+++ b/.gitlab-ci.yml
@@ -11,7 +11,7 @@ include:
 
 # For jobs that run backend scripts directly
 .backend-setup:
-  image: registry.gitlab.com/teklia/arkindex/backend/base:django-4.0.4
+  image: registry.gitlab.com/teklia/arkindex/backend/base:django-4.1.4
 
   cache:
     paths:
diff --git a/Dockerfile b/Dockerfile
index f14d885de2..922b2d6223 100644
--- a/Dockerfile
+++ b/Dockerfile
@@ -1,10 +1,10 @@
-FROM registry.gitlab.com/teklia/arkindex/backend/base:django-4.0.4 as build
+FROM registry.gitlab.com/teklia/arkindex/backend/base:django-4.1.4 as build
 
 RUN mkdir build
 ADD . build
 RUN cd build && python3 setup.py sdist
 
-FROM registry.gitlab.com/teklia/arkindex/backend/base:django-4.0.4
+FROM registry.gitlab.com/teklia/arkindex/backend/base:django-4.1.4
 ARG PONOS_BRANCH=master
 ARG PONOS_ID=10017043
 ARG TRANSKRIBUS_BRANCH=master
diff --git a/Dockerfile.binary b/Dockerfile.binary
index 9eb9efb070..04b1639f9d 100644
--- a/Dockerfile.binary
+++ b/Dockerfile.binary
@@ -60,7 +60,7 @@ RUN python -m nuitka \
       arkindex/manage.py
 
 # Start over from a clean setup
-FROM registry.gitlab.com/teklia/arkindex/backend/base:django-4.0.4 as build
+FROM registry.gitlab.com/teklia/arkindex/backend/base:django-4.1.4 as build
 
 # Import files from compilation
 RUN mkdir /usr/share/arkindex
diff --git a/arkindex/documents/__init__.py b/arkindex/documents/__init__.py
index f455a859c4..e69de29bb2 100644
--- a/arkindex/documents/__init__.py
+++ b/arkindex/documents/__init__.py
@@ -1 +0,0 @@
-default_app_config = 'arkindex.documents.apps.DocumentsConfig'
diff --git a/arkindex/images/serializers.py b/arkindex/images/serializers.py
index 050d6dd187..52c21741d0 100644
--- a/arkindex/images/serializers.py
+++ b/arkindex/images/serializers.py
@@ -190,12 +190,10 @@ class ImagePathDefault(object):
     Required because the implicit UniqueTogetherValidator in the Image serializer requires
     both server and path to either be required or have a default value.
     """
+    requires_context = True
 
-    def set_context(self, serializer_field):
-        self.serializer = serializer_field.parent
-
-    def __call__(self):
-        return str(self.serializer.fields['id'].default)
+    def __call__(self, serializer_field):
+        return str(serializer_field.parent.fields['id'].default)
 
 
 class ImageUploadSerializer(ImageSerializer):
diff --git a/arkindex/process/__init__.py b/arkindex/process/__init__.py
index fc4bfc3f7c..e69de29bb2 100644
--- a/arkindex/process/__init__.py
+++ b/arkindex/process/__init__.py
@@ -1 +0,0 @@
-default_app_config = 'arkindex.process.apps.ProcessConfig'
diff --git a/arkindex/project/aws.py b/arkindex/project/aws.py
index 0e97f1325c..3485e9e28c 100644
--- a/arkindex/project/aws.py
+++ b/arkindex/project/aws.py
@@ -92,7 +92,7 @@ class S3FileMixin(object):
             return
         return s3.Object(self.s3_bucket, self.s3_key)
 
-    s3_object = cached_property(get_s3_object, name='s3_object')
+    s3_object = cached_property(get_s3_object)
     s3_region = settings.AWS_REGION
 
     @property
diff --git a/arkindex/project/settings.py b/arkindex/project/settings.py
index 7e79e251b4..618b3f6a96 100644
--- a/arkindex/project/settings.py
+++ b/arkindex/project/settings.py
@@ -89,6 +89,17 @@ DEBUG = ARKINDEX_ENV == 'dev'
 # Run all system checks when starting the server
 ALL_CHECKS = os.environ.get('ALL_CHECKS') == 'true' or 'runserver' in sys.argv
 
+SILENCED_SYSTEM_CHECKS = [
+    # The metadata_numeric_values check constraint uses raw SQL to validate that the value
+    # can be cast into a float by PostgreSQL. This causes Django to show a warning as raw SQL
+    # expressions cannot be checked in Model.full_clean, and this will cause HTTP 500 errors
+    # in Django forms using MetaData. We only have forms in the Django admin, and MetaData
+    # can be edited just fine in the API, so this does not affect us much.
+    # Silenced in https://gitlab.com/teklia/arkindex/backend/-/merge_requests/1719
+    # Will be fixed in https://gitlab.com/teklia/arkindex/backend/-/issues/1001
+    'models.W045',
+]
+
 # Required for django-debug-toolbar
 INTERNAL_IPS = ['127.0.0.1', '127.0.1.1']
 
@@ -184,8 +195,6 @@ TIME_ZONE = 'UTC'
 
 USE_I18N = True
 
-USE_L10N = True
-
 USE_TZ = True
 
 
diff --git a/arkindex/project/tests/test_argparse.py b/arkindex/project/tests/test_argparse.py
index 20fefbec77..ee806455aa 100644
--- a/arkindex/project/tests/test_argparse.py
+++ b/arkindex/project/tests/test_argparse.py
@@ -26,7 +26,7 @@ class TestArgparseHelpers(FixtureTestCase):
     def test_corpus_argument_many(self):
         arg = CorpusArgument(many=True)
         result = arg('tests')
-        self.assertQuerysetEqual(result, [repr(self.corpus), ])
+        self.assertQuerysetEqual(result, [self.corpus, ])
 
     def test_corpus_argument_not_found(self):
         arg = CorpusArgument()
@@ -61,7 +61,7 @@ class TestArgparseHelpers(FixtureTestCase):
     def test_element_argument_many(self):
         arg = ElementArgument(type__folder=True, many=True)
         result = arg('volume 1')
-        self.assertQuerysetEqual(result, [repr(self.vol), ])
+        self.assertQuerysetEqual(result, [self.vol, ])
 
     def test_element_argument_multiple(self):
         arg = ElementArgument()
diff --git a/arkindex/sql_validation/corpus_right_access.sql b/arkindex/sql_validation/corpus_right_access.sql
index 3f0c521720..b2d4304767 100644
--- a/arkindex/sql_validation/corpus_right_access.sql
+++ b/arkindex/sql_validation/corpus_right_access.sql
@@ -14,7 +14,7 @@ WHERE ("django_content_type"."app_label" = 'users'
        AND "django_content_type"."model" = 'group')
 LIMIT 21;
 
-SELECT (1) AS "a"
+SELECT 1 AS "a"
 FROM "users_right"
 LEFT OUTER JOIN "users_group" ON ("users_right"."group_id" = "users_group"."id")
 LEFT OUTER JOIN "users_right" T5 ON ("users_group"."id" = T5."content_id"
diff --git a/arkindex/sql_validation/element_move_with_children.sql b/arkindex/sql_validation/element_move_with_children.sql
index f9425214d7..7016a3edc9 100644
--- a/arkindex/sql_validation/element_move_with_children.sql
+++ b/arkindex/sql_validation/element_move_with_children.sql
@@ -7,13 +7,13 @@ WHERE "documents_element"."id" IN
 
 SAVEPOINT "{savepoints[0]}";
 
-SELECT (1) AS "a"
+SELECT 1 AS "a"
 FROM "documents_elementpath"
 WHERE ("documents_elementpath"."element_id" = '{source_id}'::uuid
        AND "documents_elementpath"."path"[array_length("documents_elementpath"."path", 1)] = '{parent_id}'::uuid)
 LIMIT 1;
 
-SELECT (1) AS "a"
+SELECT 1 AS "a"
 FROM "documents_elementpath"
 WHERE ("documents_elementpath"."element_id" = '{source_id}'::uuid
        AND NOT ("documents_elementpath"."path"[array_length("documents_elementpath"."path", 1)] = '{parent_id}'::uuid))
diff --git a/arkindex/sql_validation/element_move_without_child.sql b/arkindex/sql_validation/element_move_without_child.sql
index 306605e8cb..017a79576b 100644
--- a/arkindex/sql_validation/element_move_without_child.sql
+++ b/arkindex/sql_validation/element_move_without_child.sql
@@ -7,13 +7,13 @@ WHERE "documents_element"."id" IN
 
 SAVEPOINT "{savepoints[0]}";
 
-SELECT (1) AS "a"
+SELECT 1 AS "a"
 FROM "documents_elementpath"
 WHERE ("documents_elementpath"."element_id" = '{source_id}'::uuid
        AND "documents_elementpath"."path"[array_length("documents_elementpath"."path", 1)] = '{parent_id}'::uuid)
 LIMIT 1;
 
-SELECT (1) AS "a"
+SELECT 1 AS "a"
 FROM "documents_elementpath"
 WHERE ("documents_elementpath"."element_id" = '{source_id}'::uuid
        AND NOT ("documents_elementpath"."path"[array_length("documents_elementpath"."path", 1)] = '{parent_id}'::uuid))
diff --git a/arkindex/sql_validation/process_elements_filter_type.sql b/arkindex/sql_validation/process_elements_filter_type.sql
index 65544a283b..7a31d9e79d 100644
--- a/arkindex/sql_validation/process_elements_filter_type.sql
+++ b/arkindex/sql_validation/process_elements_filter_type.sql
@@ -56,7 +56,7 @@ FROM "documents_corpus"
 WHERE "documents_corpus"."id" = '{corpus_id}'::uuid
 LIMIT 21;
 
-SELECT (1) AS "a"
+SELECT 1 AS "a"
 FROM "documents_element"
 INNER JOIN "process_processelement" ON ("documents_element"."id" = "process_processelement"."element_id")
 WHERE "process_processelement"."process_id" = '{process_id}'::uuid
diff --git a/arkindex/sql_validation/process_elements_top_level.sql b/arkindex/sql_validation/process_elements_top_level.sql
index 72ff6bbbaa..32b20e910c 100644
--- a/arkindex/sql_validation/process_elements_top_level.sql
+++ b/arkindex/sql_validation/process_elements_top_level.sql
@@ -56,7 +56,7 @@ FROM "documents_corpus"
 WHERE "documents_corpus"."id" = '{corpus_id}'::uuid
 LIMIT 21;
 
-SELECT (1) AS "a"
+SELECT 1 AS "a"
 FROM "documents_element"
 INNER JOIN "process_processelement" ON ("documents_element"."id" = "process_processelement"."element_id")
 WHERE "process_processelement"."process_id" = '{process_id}'::uuid
diff --git a/arkindex/sql_validation/process_elements_with_image.sql b/arkindex/sql_validation/process_elements_with_image.sql
index 135982d32b..c82ac3290a 100644
--- a/arkindex/sql_validation/process_elements_with_image.sql
+++ b/arkindex/sql_validation/process_elements_with_image.sql
@@ -56,7 +56,7 @@ FROM "documents_corpus"
 WHERE "documents_corpus"."id" = '{corpus_id}'::uuid
 LIMIT 21;
 
-SELECT (1) AS "a"
+SELECT 1 AS "a"
 FROM "documents_element"
 INNER JOIN "process_processelement" ON ("documents_element"."id" = "process_processelement"."element_id")
 WHERE "process_processelement"."process_id" = '{process_id}'::uuid
diff --git a/arkindex/users/__init__.py b/arkindex/users/__init__.py
index 1cfa95c54f..e69de29bb2 100644
--- a/arkindex/users/__init__.py
+++ b/arkindex/users/__init__.py
@@ -1 +0,0 @@
-default_app_config = 'arkindex.users.apps.UsersConfig'
diff --git a/base/requirements.txt b/base/requirements.txt
index 18da32f978..5ea2b7f0ae 100644
--- a/base/requirements.txt
+++ b/base/requirements.txt
@@ -1,5 +1,5 @@
 boto3==1.18.13
 cryptography==3.4.7
-Django==4.0.4
+Django==4.1.4
 lxml==4.6.3
 psycopg2-binary==2.9.1
-- 
GitLab