Skip to content

Port to Django 5.2 - #635

Open
FreneticScribbler wants to merge 23 commits into
masterfrom
django5
Open

FreneticScribbler wants to merge 23 commits into
masterfrom
django5

Conversation

@FreneticScribbler

Copy link
Copy Markdown
Member

Dockerfile is not very well optimised, it currently produces a 1.66GB image!!

Probably think about switching to using docker / postgres DB in development workflow, using sqlite has caused owt but problems in the past. Some work has been done to that end in this PR, much remains.

Caveat emptor

Any newer and the mystery importlib metadata error appears. Weird! >_>
Having two distinct test flavours is giving me a headache
Makes a VERY big image, I suspect we can optimise this a lot...

@code-review-doctor code-review-doctor Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Worth considering. View full project report here.

Comment thread PyRIGS/settings.py
'NAME': str(BASE_DIR / 'db.sqlite3'),
}
'default': {
'ENGINE': 'django.db.backends.{}'.format(

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

f-string is easier to read, write, and less computationally expensive than legacy string formatting. Explained here.

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

oh shut up you

@FreneticScribbler

Copy link
Copy Markdown
Member Author

Should look at updating python from 3.10 at some point too. And probably defining it in a single source of truth - currently it's manually defined in the dockerfile

@jb3 jb3 left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Overall looks good, I haven't yet tested this properly locally so the below is just a code review.

There may be some other bits that present themselves when trying to get this running but this is just a preliminary pass.

Comment thread PyRIGS/settings.py
Comment on lines +32 to +35
CSRF_TRUSTED_ORIGINS = [f"http://{host}" for host in ALLOWED_HOSTS]
CSRF_TRUSTED_ORIGINS.append("http://localhost:8000")
CSRF_TRUSTED_ORIGINS.append("http://localhost:8001")
ALLOWED_HOSTS = ['*']

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We probably want some of these CSRF variables for production, there were behaviour changes here in Django 5.

Comment thread scripts/certbot-issue.sh
cp -fL "\$RENEWED_LINEAGE/fullchain.pem" "$CERTS_DIR/fullchain.pem"
cp -fL "\$RENEWED_LINEAGE/privkey.pem" "$CERTS_DIR/privkey.pem"
chmod 600 "$CERTS_DIR/privkey.pem"
docker compose -f "$REPO_DIR/compose.yml" exec -T nginx nginx -s reload || true

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We probably don't want to silently ignore this? Why have we got || true?

Comment thread .dockerignore
nginx/
*.pem
*.key
.env.*

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We probably want to catch .env generally, not just .env.*, secrets should never be in container images.

Comment thread .dockerignore

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is a little bit unwieldy.

Have you considered instead excluding everything (*) and then using inverse operators to explicitly include the files that you do wish to be in the container?

Comment on lines +53 to +55
--ignore=RIGS/tests/test_interaction.py \
--ignore=assets/tests/test_interaction.py \
--ignore=training/tests/test_interaction.py

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Shouldn't really be done here, we should either remove those tests files if they are just totally useless or fix them. We shouldn't be making excludes like this at the CI workflow level.

Comment thread Dockerfile
@@ -0,0 +1,54 @@
# Stage 1: Base build stage
FROM combos/python_node:3.12_22 AS base

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can we not use any later version than Python 3.12 and Node 22?

Node 22 is already in maintenance and nearing EOL, and given the update frequency to RIGS it'd be nice to be on a longer supported Python version as well.

Comment thread PyRIGS/urls.py
# import debug_toolbar
urlpatterns += [
path('__debug__/', include(debug_toolbar.urls)),
# path('__debug__/', include(debug_toolbar.urls)),

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

May as well be removed or locked behind an env var, no point leaving this as commented out code.

Comment thread pyproject.toml
"asgiref",
"beautifulsoup4",
"Brotli",
"dj-database-url",

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think the usage of this is also removed.

Comment thread PyRIGS/views.py
from assets import models as asset_models
from training import models as training_models

# Template context processor

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Not really a helpful comment.

Either remove it or add it as a docstring to what you're actually describing (multiline """ string at start of function).

Comment thread PyRIGS/views.py
# Template context processor


def is_ajax(request):

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Highlighted elsewhere with the couple of instances I spotted, but worth double checking all calls of is_ajax.

This method was previously assumed to return a boolean, always returning a non-empty dict means that for ALL previous callers the return is effectively True (as a non-empty dict is truthy in Python). This is a pretty large API change and so is worth double checking all your calls.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants