Repository: Software-Engineering-Jagiellonian/django-celery-frege
Pull request #113: chore: bump django and python version
Author: login: Gochad
Created: 2025-03-20T21:16:18Z | Merged: 2025-03-27T18:06:14Z

- bump django to v5.1.7 & python to 3.13
- fix not backward compatible time conversion in django 5.1.7 for one migration
- fix static files for django dev

Helpful documentation for setup whitenoise: https://whitenoise.readthedocs.io/en/latest/#quickstart-for-django-apps

### results:
![Screenshot (6)](https://github.com/user-attachments/assets/aa725316-a940-440b-bb0d-a8022cba271b)
![Screenshot (9)](https://github.com/user-attachments/assets/6609b426-ab6f-4016-b823-5a0438bfd18d)



Diff:
diff --git a/.env.template b/.env.template
index 18475e96..21c459c7 100644
--- a/.env.template
+++ b/.env.template
@@ -22,7 +22,7 @@ DJANGO_REDIS_PORT=6379
 DJANGO_REDIS_HOST=frege-redis
 
 DJANGO_SECRET_KEY=
-DJANGO_DEBUG=False
+DJANGO_DEBUG=True
 DJANGO_DOWNLOAD_PATH=/var/tmp/frege/
 DOWNLOAD_DIR_MAX_SIZE_BYTES=2000000000
 DOWNLOAD_TASK_NAME=celery@worker_downloads
diff --git a/backend/.gitignore b/backend/.gitignore
index 701a37fc..7ca1c357 100644
--- a/backend/.gitignore
+++ b/backend/.gitignore
@@ -14,7 +14,7 @@ settingsOLD.py
 
 # If your build process includes running collectstatic, then you probably don't need or want to include staticfiles/
 # in your Git repository. Update and uncomment the following line accordingly.
-# <django-project-name>/staticfiles/
+static/
 
 ### Django.Python Stack ###
 # Byte-compiled / optimized / DLL files
diff --git a/backend/Dockerfile b/backend/Dockerfile
index 89291be7..576a00a0 100644
--- a/backend/Dockerfile
+++ b/backend/Dockerfile
@@ -1,4 +1,4 @@
-FROM python:3.10
+FROM python:3.13
 ENV PYTHONUNBUFFERED=1
 WORKDIR /app
 COPY requirements.txt requirements.txt
@@ -7,3 +7,4 @@ RUN pip install gunicorn==20.1.0
 COPY download_nltk_data.py download_nltk_data.py
 RUN python download_nltk_data.py
 COPY . .
+
diff --git a/backend/frege/indexers/migrations/0005_add_bitbucketindexer.py b/backend/frege/indexers/migrations/0005_add_bitbucketindexer.py
index 2b4e0248..e71170ea 100644
--- a/backend/frege/indexers/migrations/0005_add_bitbucketindexer.py
+++ b/backend/frege/indexers/migrations/0005_add_bitbucketindexer.py
@@ -3,8 +3,7 @@
 import datetime
 
 from django.db import migrations, models
-from django.utils.timezone import utc
-
+from datetime import timezone
 
 class Migration(migrations.Migration):
 
@@ -41,9 +40,7 @@ class Migration(migrations.Migration):
                 (
                     "current_date",
                     models.DateTimeField(
-                        default=datetime.datetime(
-                            1970, 1, 1, 0, 0, tzinfo=utc
-                        ),
+                        default=datetime.datetime(1970, 1, 1, 0, 0),
                         help_text="The creation date of repository from which to start searching. Please note that Bitbucket API paginates repos by creation date, so the dates are used to iterate over repositories.",
                         verbose_name="current date",
                     ),
diff --git a/backend/frege/settings.py b/backend/frege/settings.py
index c42fde23..24d43b61 100644
--- a/backend/frege/settings.py
+++ b/backend/frege/settings.py
@@ -1,11 +1,3 @@
-"""
-Django settings for frege project.
-Generated by 'django-admin startproject' using Django 4.0.3.
-For more information on this file, see
-https://docs.djangoproject.com/en/4.0/topics/settings/
-For the full list of settings and their values, see
-https://docs.djangoproject.com/en/4.0/ref/settings/
-"""
 import os
 from pathlib import Path
 
@@ -39,7 +31,6 @@
 ]
 
 EXTERNAL_APPS = [
-    "jazzmin",
     "django.contrib.admin",
     "django.contrib.auth",
     "django.contrib.contenttypes",
@@ -74,6 +65,7 @@
     "django.contrib.auth.middleware.AuthenticationMiddleware",
     "django.contrib.messages.middleware.MessageMiddleware",
     "django.middleware.clickjacking.XFrameOptionsMiddleware",
+    "whitenoise.middleware.WhiteNoiseMiddleware",
 ]
 
 ROOT_URLCONF = "frege.urls"
@@ -131,13 +123,11 @@
 
 USE_TZ = True
 
+STATIC_URL = '/static/'
+STATIC_ROOT = os.path.join(BASE_DIR, 'static')
 
-# Static files (CSS, JavaScript, Images)
-# https://docs.djangoproject.com/en/4.0/howto/static-files/
-
-STATIC_URL = "api_static/"
-STATIC_ROOT = BASE_DIR / "static"
-
+MEDIA_URL = "/media/"
+MEDIA_ROOT = os.path.join(BASE_DIR, 'media')
 # Default primary key field type
 # https://docs.djangoproject.com/en/4.0/ref/settings/#default-auto-field
 
@@ -187,12 +177,15 @@
 # MISC
 
 DOWNLOAD_PATH = os.environ.get("DJANGO_DOWNLOAD_PATH", "/var/tmp/frege/")
+
 DOWNLOAD_DIR_MAX_SIZE_BYTES = int(
     os.environ.get("DOWNLOAD_DIR_MAX_SIZE_BYTES", "2000000000")
 )
+
 DOWNLOAD_TASK_NAME = os.environ.get(
     "DOWNLOAD_TASK_NAME", "celery@worker_downloads"
 )
+
 MAX_DOWNLOAD_TASKS_COUNT = int(
     os.environ.get("MAX_DOWNLOAD_TASKS_COUNT", "24")
 )
@@ -254,6 +247,7 @@
     'DISK_USAGE_MAX': 70,  # percent
     'MEMORY_MIN': 100,    # in MB
 }
+
 REDIS_URL = f"redis://{REDIS_HOST}:{REDIS_PORT}/"
 # CELERY_BROKER_URL = f"redis://{REDIS_HOST}:{REDIS_PORT}/"
 # CELERY_RESULT_BACKEND = f"redis://{REDIS_HOST}:{REDIS_PORT}/"
diff --git a/backend/frege/urls.py b/backend/frege/urls.py
index 59dd27f1..2f5b2a93 100644
--- a/backend/frege/urls.py
+++ b/backend/frege/urls.py
@@ -16,6 +16,7 @@
 from django.contrib import admin
 from django.urls import include, path
 from django.views.generic import RedirectView
+from django.conf import settings
 from rest_framework import routers
 
 from frege.repositories.consumers import LiveStatusConsumer
diff --git a/backend/frege/wsgi.py b/backend/frege/wsgi.py
index 4ae61ed6..00e1e780 100644
--- a/backend/frege/wsgi.py
+++ b/backend/frege/wsgi.py
@@ -1,16 +1,11 @@
-"""
-WSGI config for frege project.
-
-It exposes the WSGI callable as a module-level variable named ``application``.
-
-For more information on this file, see
-https://docs.djangoproject.com/en/4.0/howto/deployment/wsgi/
-"""
-
 import os
-
 from django.core.wsgi import get_wsgi_application
+from django.conf import settings
+from whitenoise import WhiteNoise
 
 os.environ.setdefault("DJANGO_SETTINGS_MODULE", "frege.settings")
 
 application = get_wsgi_application()
+
+application = WhiteNoise(application, root=settings.STATIC_ROOT)
+application.add_files(settings.MEDIA_ROOT, prefix='media')
diff --git a/backend/requirements.txt b/backend/requirements.txt
index a1151da3..047dc6da 100644
--- a/backend/requirements.txt
+++ b/backend/requirements.txt
@@ -1,14 +1,12 @@
-# Project dependencies:
-Django~=4.0.4
-djangorestframework~=3.13.1
-django-extensions~=3.1.5
-celery[redis]~=5.2.6
+Django==5.1.7
+djangorestframework==3.15.2
+django-extensions~=3.2.3
+celery[redis]==5.4.0
 psycopg2~=2.9.3
 Faker~=13.6.0
 GitPython~=3.1.27
 radon~=5.1.0
 flower~=1.0.0
-django-jazzmin~=2.5.0
 PyGithub~=1.55
 lizard~=1.17.10
 factory-boy~=3.2.1
@@ -17,27 +15,21 @@ requests~=2.27.1
 beautifulsoup4~=4.9.3
 django-cors-headers~=3.11.0
 djangorestframework-api-key~=2.2.0
-channels~=3.0.4
-channels-redis~=3.4.0
-djangochannelsrestframework~=1.0.0
-django-health-check~=3.17.0
+channels==4.1.0
+channels-redis==4.0.0
+djangochannelsrestframework==1.3.0
+django-health-check~=3.18.3
 psutil~=5.9.4
-nltk==3.8.1
+nltk==3.9.1
 textstat==0.7.3
 
-# Currently unused/useful for later:
-# django-redis
-
-# django-celery-beat==2.1.0
-# django-celery-results
-# websockets
 # Development tools:
 black~=22.3.0
 isort~=5.10.1
 flake8~=4.0.1
 pre-commit~=2.18.1
 pyupgrade~=3.3.1
-gitlint~=0.18.0
+gitlint==0.19.1
 
 # Testing
 pytest~=7.1.2
@@ -45,3 +37,5 @@ pytest-mock~=3.7.0
 pytest-unordered~=0.4.1
 pytest-django~=4.5.2
 pytest-asyncio~=0.18.3
+
+whitenoise==6.9.0
diff --git a/docker-compose.yml b/docker-compose.yml
index ae54ed21..2834aae2 100644
--- a/docker-compose.yml
+++ b/docker-compose.yml
@@ -129,6 +129,15 @@ services:
 
   frege-backend-dev:
     <<: *backend
+    volumes:
+      - ./backend:/app
+      - frege_tmp:${DJANGO_DOWNLOAD_PATH}
+      - ./backend/static:/app/static
+    command: >
+      sh -c "python manage.py migrate --noinput
+      && python manage.py initadmin
+      && python manage.py collectstatic --noinput
+      && python manage.py runserver 0.0.0.0:${DOCKER_BACKEND_PORT}"
     healthcheck:
       test: "curl -f http://localhost:${DOCKER_BACKEND_PORT}/ht || exit 1"
       interval: 10s
diff --git a/nginx/egress.nginx.conf b/nginx/egress.nginx.conf
index eaa076e7..6cef2fb3 100644
--- a/nginx/egress.nginx.conf
+++ b/nginx/egress.nginx.conf
@@ -359,7 +359,7 @@ server {
 		{{ end }}
 	}
 
-	location /api_static/ {
+	location /static/ {
 		autoindex off;
 		alias /var/www/backend/static/;
 	}
@@ -416,7 +416,7 @@ server {
 		{{ end }}
 	}
 
-	location /api_static/ {
+	location /static/ {
 		autoindex off;
 		alias /var/www/backend/static/;
 	}


Reviews:
user: login: iza133
state: APPROVED
author_association: CONTRIBUTOR
submitted_at: 2025-03-24T08:04:00Z
user: login: iza133
body: So sorry, I messed up links, I approved wrong PR :D
state: DISMISSED
author_association: CONTRIBUTOR
submitted_at: 2025-03-24T08:07:18Z
user: login: tjzel
state: COMMENTED
author_association: CONTRIBUTOR
submitted_at: 2025-03-24T19:33:36Z
user: login: Gochad
state: COMMENTED
author_association: CONTRIBUTOR
submitted_at: 2025-03-24T20:12:49Z
user: login: Gochad
state: COMMENTED
author_association: CONTRIBUTOR
submitted_at: 2025-03-24T20:13:42Z
user: login: Gochad
state: COMMENTED
author_association: CONTRIBUTOR
submitted_at: 2025-03-24T20:13:52Z
user: login: Gochad
state: COMMENTED
author_association: CONTRIBUTOR
submitted_at: 2025-03-24T20:16:37Z
user: login: tjzel
state: COMMENTED
author_association: CONTRIBUTOR
submitted_at: 2025-03-25T18:50:18Z
user: login: Gochad
state: COMMENTED
author_association: CONTRIBUTOR
submitted_at: 2025-03-26T21:32:26Z
user: login: copilot-pull-request-reviewer[bot]
body: ## Pull Request Overview

This PR bumps Django to v5.1.7 and Python to 3.13 while addressing compatibility issues with time conversion and updating static file handling.  
- Bump dependency versions for Django and Python.  
- Adjust migration default datetime to address backward compatibility.  
- Integrate WhiteNoise for static and media file handling in both WSGI and settings.

### Reviewed Changes

Copilot reviewed 5 out of 10 changed files in this pull request and generated 1 comment.

<details>
<summary>Show a summary per file</summary>

| File                                                   | Description                                                                |
| ------------------------------------------------------ | -------------------------------------------------------------------------- |
| backend/frege/wsgi.py                                  | Adds WhiteNoise configuration to serve static and media files.           |
| docker-compose.yml                                     | Updates volume mappings & startup command to accommodate static files.     |
| backend/frege/settings.py                              | Revises STATIC/MEDIA settings and adds WhiteNoise middleware.              |
| backend/frege/indexers/migrations/0005_add_bitbucketindexer.py | Modifies migration default datetime to address timezone conversion issues. |
| backend/frege/urls.py                                  | Adds settings import (unused in the diff) for potential future references. |
</details>


<details>
<summary>Files not reviewed (5)</summary>

* **.env.template**: Language not supported
* **backend/.gitignore**: Language not supported
* **backend/Dockerfile**: Language not supported
* **backend/requirements.txt**: Language not supported
* **nginx/egress.nginx.conf**: Language not supported
</details>

<details>
<summary>Comments suppressed due to low confidence (1)</summary>

**backend/frege/settings.py:127**
* Using os.path.join with a pathlib.Path object may produce unexpected results. Consider using BASE_DIR / 'static' for consistency.
```
STATIC_ROOT = os.path.join(BASE_DIR, 'static')
```
</details>


state: COMMENTED
author_association: NONE
submitted_at: 2025-03-26T22:46:13Z
user: login: tjzel
body: Let's merge this bad boy
state: APPROVED
author_association: CONTRIBUTOR
submitted_at: 2025-03-27T13:45:53Z

Review comments:
diff_hunk: @@ -1,9 +1,10 @@
-FROM python:3.10
+FROM python:3.13
 ENV PYTHONUNBUFFERED=1
 WORKDIR /app
 COPY requirements.txt requirements.txt
-RUN pip install -r ./requirements.txt
-RUN pip install gunicorn==20.1.0
+RUN pip install --no-cache-dir -r ./requirements.txt
+RUN pip install --no-cache-dir gunicorn==20.1.0
path: backend/Dockerfile
user: login: tjzel
body: Why do we need this?
created_at: 2025-03-24T19:30:45Z
author_association: CONTRIBUTOR
diff_hunk: @@ -31,17 +29,20 @@ textstat==0.7.3
 # django-celery-beat==2.1.0
 # django-celery-results
 # websockets
+
 # Development tools:
 black~=22.3.0
 isort~=5.10.1
 flake8~=4.0.1
 pre-commit~=2.18.1
 pyupgrade~=3.3.1
-gitlint~=0.18.0
+gitlint
path: backend/requirements.txt
user: login: tjzel
body: Why unversioned?
created_at: 2025-03-24T19:31:48Z
author_association: CONTRIBUTOR
diff_hunk: @@ -31,17 +29,20 @@ textstat==0.7.3
 # django-celery-beat==2.1.0
 # django-celery-results
 # websockets
+
 # Development tools:
 black~=22.3.0
 isort~=5.10.1
 flake8~=4.0.1
 pre-commit~=2.18.1
 pyupgrade~=3.3.1
-gitlint~=0.18.0
+gitlint
 
 # Testing
 pytest~=7.1.2
 pytest-mock~=3.7.0
 pytest-unordered~=0.4.1
 pytest-django~=4.5.2
 pytest-asyncio~=0.18.3
+
+whitenoise
path: backend/requirements.txt
user: login: tjzel
body: Why unversioned?
created_at: 2025-03-24T19:31:52Z
author_association: CONTRIBUTOR
diff_hunk: @@ -129,6 +129,15 @@ services:
 
   frege-backend-dev:
     <<: *backend
+    volumes:
+      - ./backend:/app
+      - frege_tmp:${DJANGO_DOWNLOAD_PATH}
+      - ./backend/static:/app/static
+    command: >
+      sh -c "python manage.py migrate --noinput
+      && python manage.py initadmin
+      && python manage.py collectstatic --noinput
+      && python manage.py runserver 0.0.0.0:${DOCKER_BACKEND_PORT}"
path: docker-compose.yml
user: login: tjzel
body: Why do we need this now?
created_at: 2025-03-24T19:33:29Z
author_association: CONTRIBUTOR
diff_hunk: @@ -129,6 +129,15 @@ services:
 
   frege-backend-dev:
     <<: *backend
+    volumes:
+      - ./backend:/app
+      - frege_tmp:${DJANGO_DOWNLOAD_PATH}
+      - ./backend/static:/app/static
+    command: >
+      sh -c "python manage.py migrate --noinput
+      && python manage.py initadmin
+      && python manage.py collectstatic --noinput
+      && python manage.py runserver 0.0.0.0:${DOCKER_BACKEND_PORT}"
path: docker-compose.yml
user: login: Gochad
body: It's needed to collecting static files on docker container
created_at: 2025-03-24T20:12:49Z
author_association: CONTRIBUTOR
diff_hunk: @@ -31,17 +29,20 @@ textstat==0.7.3
 # django-celery-beat==2.1.0
 # django-celery-results
 # websockets
+
 # Development tools:
 black~=22.3.0
 isort~=5.10.1
 flake8~=4.0.1
 pre-commit~=2.18.1
 pyupgrade~=3.3.1
-gitlint~=0.18.0
+gitlint
path: backend/requirements.txt
user: login: Gochad
body: because this version is conflicted with black and new django - i let pip to choose their own suitable version
created_at: 2025-03-24T20:13:42Z
author_association: CONTRIBUTOR
diff_hunk: @@ -1,9 +1,10 @@
-FROM python:3.10
+FROM python:3.13
 ENV PYTHONUNBUFFERED=1
 WORKDIR /app
 COPY requirements.txt requirements.txt
-RUN pip install -r ./requirements.txt
-RUN pip install gunicorn==20.1.0
+RUN pip install --no-cache-dir -r ./requirements.txt
+RUN pip install --no-cache-dir gunicorn==20.1.0
path: backend/Dockerfile
user: login: Gochad
body: probably we don't need 🤔 i'll remove
created_at: 2025-03-24T20:13:52Z
author_association: CONTRIBUTOR
diff_hunk: @@ -31,17 +29,20 @@ textstat==0.7.3
 # django-celery-beat==2.1.0
 # django-celery-results
 # websockets
+
 # Development tools:
 black~=22.3.0
 isort~=5.10.1
 flake8~=4.0.1
 pre-commit~=2.18.1
 pyupgrade~=3.3.1
-gitlint~=0.18.0
+gitlint
 
 # Testing
 pytest~=7.1.2
 pytest-mock~=3.7.0
 pytest-unordered~=0.4.1
 pytest-django~=4.5.2
 pytest-asyncio~=0.18.3
+
+whitenoise
path: backend/requirements.txt
user: login: Gochad
body: because I want to download the newest - I will add
created_at: 2025-03-24T20:16:37Z
author_association: CONTRIBUTOR
diff_hunk: @@ -31,17 +29,20 @@ textstat==0.7.3
 # django-celery-beat==2.1.0
 # django-celery-results
 # websockets
+
 # Development tools:
 black~=22.3.0
 isort~=5.10.1
 flake8~=4.0.1
 pre-commit~=2.18.1
 pyupgrade~=3.3.1
-gitlint~=0.18.0
+gitlint
path: backend/requirements.txt
user: login: tjzel
body: It's usually a bad idea not to lock packages - people on the team can effectively work in different environments, there's also security concern. We should get a non-conflicting version and lock it.
created_at: 2025-03-25T18:50:18Z
author_association: CONTRIBUTOR
diff_hunk: @@ -31,17 +29,20 @@ textstat==0.7.3
 # django-celery-beat==2.1.0
 # django-celery-results
 # websockets
+
 # Development tools:
 black~=22.3.0
 isort~=5.10.1
 flake8~=4.0.1
 pre-commit~=2.18.1
 pyupgrade~=3.3.1
-gitlint~=0.18.0
+gitlint
path: backend/requirements.txt
user: login: Gochad
body: @tjzel I added the newest versions 
created_at: 2025-03-26T21:32:26Z
author_association: CONTRIBUTOR
diff_hunk: @@ -41,9 +40,7 @@ class Migration(migrations.Migration):
                 (
                     "current_date",
                     models.DateTimeField(
-                        default=datetime.datetime(
-                            1970, 1, 1, 0, 0, tzinfo=utc
-                        ),
+                        default=datetime.datetime(1970, 1, 1, 0, 0),
path: backend/frege/indexers/migrations/0005_add_bitbucketindexer.py
user: login: Copilot
body: Removing tzinfo creates a naive datetime object while USE_TZ is True. Consider including an explicit tzinfo (e.g., timezone.utc) to maintain consistency.
```suggestion
                        default=datetime.datetime(1970, 1, 1, 0, 0, tzinfo=timezone.utc),
```
created_at: 2025-03-26T22:46:13Z
author_association: NONE

PR comments:
user: login: tjzel
created_at: 2025-03-24T19:30:07Z
body: Why is this on Windows
author_association: CONTRIBUTOR
user: login: Gochad
created_at: 2025-03-24T20:17:56Z
body: > Why is this on Windows

why not? 
author_association: CONTRIBUTOR