Skip to content

Commit

Permalink
Update to Django 3.2 and update Python packages
Browse files Browse the repository at this point in the history
I can't currently update to Django 4.0 because django-formtools 2.4
includes a bug that breaks our usage case of conditional form steps on
the Outreachy initial application:

#537
jazzband/django-formtools#220

I also ran into an odd issue with the home/test_eligibility.py unit
test. The work-around is documented in the code, although Jamey Sharp
and I still have no clue as to what the root cause is.

All the other unit tests use the home/scenarios.py code, and none of
them seem to have issues.

The unit tests are now more verbose, showing the permission errors that
are uncaught, and 404 not found messages. In those cases, we're actually
trying to test that errors are thrown when pages aren't accessed
properly.

I could add more code to catch those permission errors, but
I'm too tired after wrestling with updates. That's future work.

At least we're running a Django version that is receiving security
updates now! Django 3.2 is marked as being a long-term support release,
until early 2024:

https://www.djangoproject.com/download/

However, it will be really important to upgrade to 4.2 in mid-2023, so
that we can be on the next LTS release before 3.2 is deprecated in early
2024.
  • Loading branch information
Sage Sharp committed Dec 29, 2022
1 parent 0b8b54a commit 1af2d20
Show file tree
Hide file tree
Showing 8 changed files with 314 additions and 294 deletions.
22 changes: 8 additions & 14 deletions Pipfile
Original file line number Diff line number Diff line change
Expand Up @@ -6,37 +6,31 @@ name = "pypi"
[packages]
dj-database-url = "*"
dj-static = "*"
django = "<3.2"
django = "~=3.2"
django-ckeditor = "*"
django-compressor = "*"
django-compressor-postcss = "*"
django-contact-form = "*"
django-debug-toolbar = "*"
django-extensions = "*"
django-formtools = "*"
django-formtools = "==2.3"
django-libsass = "*"
django-markdownx = "*"
django-registration = "*"
django-reversion = "<4.0"
django-timezone-field = "*"
gunicorn = "*"
"psycopg2" = "*"
psycopg2 = "*"
pytz = "==2021.1"
raven = "*"
wagtail = "*"
whitenoise = "*"

# django-betterforms is unmaintained but this fork works
django-betterforms = {git = "https://github.com/jpic/django-betterforms.git"}

# Not used in the code outside the test suite, but useful in the Django shell
# on the deployed site, so it's here instead of dev-packages.
factory_boy = "*"

# No longer used anywhere but still required until we squash away the
# migrations that reference it.
django-language-field = "*"

[dev-packages]
coverage = "*"
django-coverage-plugin = "*"
"flake8" = "*"
flake8 = "*"

[packages.django-betterforms]
git = "https://github.com/jpic/django-betterforms.git"
534 changes: 261 additions & 273 deletions Pipfile.lock

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion contacts/forms.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
"""
from __future__ import unicode_literals

from contact_form.forms import ContactForm
from django_contact_form.forms import ContactForm
from django import forms

class OutreachyContactForm(ContactForm):
Expand Down
2 changes: 1 addition & 1 deletion contacts/views.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
from __future__ import unicode_literals

from .forms import OutreachyContactForm
from contact_form.views import ContactFormView
from django_contact_form.views import ContactFormView
from django.shortcuts import render
from django.urls import reverse
from django.views.generic import TemplateView
Expand Down
22 changes: 22 additions & 0 deletions home/migrations/0003_alter_homepage_body.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
# Generated by Django 3.2.16 on 2022-12-27 01:02

from django.db import migrations
import wagtail.blocks
import wagtail.contrib.table_block.blocks
import wagtail.fields
import wagtail.images.blocks


class Migration(migrations.Migration):

dependencies = [
('home', '0002_auto_20221226_2301'),
]

operations = [
migrations.AlterField(
model_name='homepage',
name='body',
field=wagtail.fields.StreamField([('heading', wagtail.blocks.CharBlock(template='home/blocks/heading.html')), ('paragraph', wagtail.blocks.RichTextBlock()), ('image', wagtail.images.blocks.ImageChooserBlock()), ('logo', wagtail.images.blocks.ImageChooserBlock(template='home/blocks/logo.html')), ('date', wagtail.blocks.DateBlock()), ('table', wagtail.contrib.table_block.blocks.TableBlock(template='home/blocks/table.html')), ('quote', wagtail.blocks.RichTextBlock(template='home/blocks/quote.html'))], use_json_field=True),
),
]
8 changes: 3 additions & 5 deletions home/models.py
Original file line number Diff line number Diff line change
Expand Up @@ -37,8 +37,6 @@
from wagtail.admin.edit_handlers import FieldPanel
from wagtail.admin.edit_handlers import InlinePanel
from wagtail.core import blocks
from wagtail.admin.edit_handlers import StreamFieldPanel
from wagtail.images.edit_handlers import ImageChooserPanel
from wagtail.images.blocks import ImageChooserBlock
from wagtail.contrib.table_block.blocks import TableBlock
from wagtail.contrib.routable_page.models import RoutablePageMixin, route
Expand Down Expand Up @@ -68,9 +66,9 @@ class HomePage(Page):
('date', blocks.DateBlock()),
('table', TableBlock(template="home/blocks/table.html")),
('quote', blocks.RichTextBlock(template="home/blocks/quote.html")),
])
], use_json_field=True)
content_panels = Page.content_panels + [
StreamFieldPanel('body', classname="full"),
FieldPanel('body', classname="full"),
]

class RichTextOnly(Page):
Expand Down Expand Up @@ -969,7 +967,7 @@ class AlumInfo(Orderable):
panels = [
FieldPanel('name'),
FieldPanel('email'),
ImageChooserPanel('picture'),
FieldPanel('picture'),
FieldPanel('gravitar'),
FieldPanel('location'),
FieldPanel('nick'),
Expand Down
6 changes: 6 additions & 0 deletions home/test_eligibility.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,12 @@ def setUpTestData(cls):
minimum_days_free_for_students=42,
minimum_days_free_for_non_students=49,
)
# As of a recent update of package dependencies on 2022-12, the code above didn't work.
# One hypothesis was that FactoryBoy was not running the full class initializer. That seems to not be the case.
# Another hypothesis involves the recent updates to Wagtail, since RoundPage is a subclass of a Wagtail Page.
# It could be that Wagtail changed the Page class so that it overrides the get_attribute method?
# In the end, we didn't figure out the root cause, but reloading the object from the database works???
cls.application_round = RoundPage.objects.get(pk=cls.application_round.pk)

all_gender_identities = (
'transgender',
Expand Down
12 changes: 12 additions & 0 deletions outreachyhome/settings/base.py
Original file line number Diff line number Diff line change
Expand Up @@ -173,6 +173,17 @@
default='sqlite:///' + os.path.join(BASE_DIR, 'db.sqlite3'))
}

# In Django 3.2, developers introduced a new way to generate object IDs (pks)
# migrating from the old method (django.db.models.AutoField)
# to the new method (django.db.models.BigAutoField)
# requires us to run an SQL query to change the IDs of all objects in our current database.
# There's no easy way to do that with the current Django migration framework.
#
# https://docs.djangoproject.com/en/3.2/ref/settings/#std-setting-DEFAULT_AUTO_FIELD
#
# For now, tell Django we are explicitly using the old ID generation method.
DEFAULT_AUTO_FIELD = 'django.db.models.AutoField'

# If an error occurs in a view, make sure none of that view's changes are saved.
ATOMIC_REQUESTS = True

Expand Down Expand Up @@ -242,6 +253,7 @@
# Wagtail settings

WAGTAIL_SITE_NAME = "outreachyhome"
WAGTAILADMIN_BASE_URL = 'https://www.outreachy.org'

# Base URL to use when referring to full URLs within the Wagtail admin backend -
# e.g. in notification emails. Don't include '/admin' or a trailing slash
Expand Down

0 comments on commit 1af2d20

Please sign in to comment.