Wagtail CMS: Updating Wagtail, Django and Django Debug Toolbar

This video is from Wagtail CMS 2023 .

Wagtail CMS: Updating Wagtail, Django and Django Debug Toolbar
0:12:12
Published November 29, 2023
1,942 views

In this video we'll go over upgrading your Wagtail website from v2.4 to v2.5.1 and we'll upgrade Django from 2.1.5 to 2.2.2. As a bonus, we'll explore an issue with Django Debug Toolbar.

Tutorial: https://learnwagtail.com/tutorials/upgrading-wagtail-to-version-2-5-1-and-django-2-2-2

Commands used:
pip install wagtail==2.5.1
pip install Django==2.2.2
pip install django-debug-toolbar==2.0a1

Updating your project:

  1. Update your repo with the new requirements.txt file (link to the commit is below)
  2. run pip install -r requirements.txt
  3. ./manage.py migrate
  4. ./manage.py runserver 0.0.0.0:8000

Git Commit: https://github.com/CodingForEverybody/learn-wagtail/commit/4efc0639b89261cdb99ca6fdf3c4a974a4ad2493

Learn Wagtail from scratch with the official Wagtail for Beginners Course
https://learnwagtail.com/wagtail-for-beginners/

Used in this video:
Wagtail 2.4 to Wagtail 2.5.1
Python 3.7
Django 2.1.5 to Django 2.2.2
Django Debug Toolbar 1.11 to 2.0a1

#Wagtail #Django #Python

Summary

The speaker upgrades a Wagtail project from 2.4 to 2.5.1 and Django from 2.1.5 to 2.2.2, checking that the site still runs before and after applying migrations. They then investigate Django Debug Toolbar errors: version 2.0a1 works but makes pages extremely slow by generating hundreds of queries, so they disable the toolbar in the development settings while leaving the configuration commented out for future use. The update also removes Wagtail’s upgrade warning, includes Django fixes and security patches, and requires updating the project’s requirements files.

Key takeaways

  • Upgrade Wagtail to 2.5.1 rather than 2.5 because it includes an important bug fix.
  • Upgrade Django to 2.2.2, then run the project’s migrations and verify the site still loads.
  • Django Debug Toolbar version 2.0a1 can work with this setup but may generate hundreds of queries and make pages take around 30 seconds to load.
  • Disable the toolbar by commenting out both its middleware and installed-app entries in the development settings.
  • Update and commit the requirements.txt and Pipfile files along with the settings changes.

Summarised automatically from the transcript.

Transcript

2,018 words · auto-generated Show

Automatically transcribed, so expect mistakes in names and technical terms.

0:00

Hello and welcome back to another lesson on learning Wagtail. In this particular video, we are going to be upgrading Wagtail from version 2. 4 to 2. 5. We're also going to upgrade Django, and because some people have been reporting some errors with Django debug toolbar, we are also going to take a look at that and see if we can either fix it or remove it. So here I'm simply going to CD into my website. And then I'm going to go into my site. And I'm just going to enter my environment with pip env shell However, if you're using Docker or Vagrant or anything else, you just need to get inside of that environment. It doesn't really matter what your environment is, just make sure you are inside of it. So I'm inside of mine and I'm going to show you what I'm using right now.

0:47

So I do pip show Wagtail and we can see here I'm using Wagtail version 2. 4. And if I do pip show django with a capital D, I'm using 2. 1. 5. And just for giggles, let's take a look at Django debug toolbar. So pip show Django debug toolbar, and you can see my command here And I'm using version 1. 11. So now before upgrading, I always like to make sure that my site is running the way it's supposed to run And for me, that's as easy as manage. py run server 000

1:33

port 8000 Life looks good. It's using my dev settings. You can see that here. And I'm just going to open up my browser. Go to localhost, port 8000. We'll see this ugly website. Yep, sure enough, there it is. Let's go to our admin and we can sign in. We can also see that debug toolbar is working perfectly fine here, although I do expect it's going to break at some point. So when we sign in we can see that Wagtail saying, oh your version is 2. 4 and it could be 2. 5. 1. So let's go ahead and upgrade that now. So let's open up our terminal, cancel that, and let's do a pip install Wagtail.

2:18

Now there's two ways we can do this. We know that there's a Wagtail 2. 5. 1 version, so we can go straight to that version and lock it here. Where we can say pip install wagtail is equal to equal to so two equal signs two five one and hit enter or we can simply upgrade By using dash dash upgrade. Now I'm going to use the upgrade version in this particular instance and just let it do its thing. So it's going to find my existing installation of Wagtel 2. 4. It's removed it and it's successfully installed Wagtail 2. 5. 1. So That's all well and good. Now let's run our server again, see. Okay, we have one unapplied migration. Alright

3:04

But we can still see that we're using Django 2. 1. 5. Now at this point you probably want to run your migration and then upgrade Django. I just know because I've done this a few times over the last few weeks that this is not a big deal. So what I'm going to do is again pip show Django and Again we can see we're using 2. 1. 5 so let's go ahead and upgrade that. So pip install Django and this time I'm just going to demonstrate that I can use the two equal signs. So pip install Django version 2. 2. 2 is the latest one. And it's uninstalling 2. 1. 5 and it's installing 2. 2. 2. Alrighty.

3:51

As you can see, my pip needs a little bit of an upgrade as well. So let's go ahead and run our server at port 8000. Now we can see we have three unapplied migrations and we just want to make sure that the site's actually going to run. Although occasionally you'll get a migration. a re a required migration rather and your site does not run. Now you saw that that alert completely went away. So that's good news. So now let's go ahead and Make these migrations. Or rather, let's go ahead and run these migrations. So we type in manage. py migrate Cool, all three of those were migrated perfectly fine. There were no problems in there. And let's run our server again.

4:40

Refresh and it's at this point that people have been saying that Django debug toolbar doesn't work. Uh it seems to be working here, but I I can only imagine that it's actually probably breaking on a particular page or a particular view. So I don't know, maybe let's just click around a little bit and see what we can find. And that one worked okay. Uh what about about page? Yeah, sure leave the page. It looks okay. View live. That looks okay. Edit. And there it is. List index out of range. Okay, so we have a couple options at this point. We can try to debug this all we like. I'm not a contributor to Django debug toolbar.

5:30

Uh nor would I really like to be, to be totally honest, so I'm not going to try to debug this too much. I'm gonna scroll down and Just take a look at some of these highlighted sections. So has safe changes? Is this throwing an error? Or is there anything near the bottom? Here there's a few in here. So there are a few highlights in here and nothing that immediately sticks out to me So instead of trying to debug this, what I'm going to do is I'm going to try to upgrade this, downgrade this, or remove Django debug toolbar, or disable it rather. So back to my terminal. I'm going to do pip show

6:15

Django debug toolbar. And I'm using version 1. 11. I can see that here. Now I want to see what other versions there are, so let's do pip install Django and there's probably a better way to do this. Django debug to bar and I'm just going to cheat by giving it some nonsense number that doesn't exist. And it says could not find a version that satisfies the requirements of 123 123 123123123. And there are, or there is, a list that we can choose from. So we have 1. 10, 1. 10. 1, 1. 11, and 2. 0a1. Now that's That's basically an alpha release or a beta release. It's really just

7:00

testing the waters right now. So this one's probably not going to work, I can imagine. But let's give it a shot anyways. So 2. 0A1. Pip install Django Debug Toolbar two point zero A one Alrighty. And I just want to rerun my server. And let's refresh this page. And it's already taking a couple seconds here, so I expect that uh one of two things is going to happen. Either this is not going to resolve itself at all, or this page is not going to be served at all. Now there's something going on in the background because my fan just fired up, so I'm assuming that this is either looping through something or this is having a really hard time trying to figure out what it's supposed to do.

7:52

Oh it worked! Look at that Amazing! Why did it take so long? It took whew! The request took so long. There are 427 queries. Wow, this is this is pretty much a mess in here. So Django debug toolbar has something that is Very inefficient in its latest release. However, this does seem to work locally, so you have that option. Now, should this have not worked for you or If it does work for you, but you're like, I'm not waiting 30 seconds to load a page. And by the way, that's totally acceptable because I'm going to be disabling this for the time being in our repo. Because people should not have to wait 30 seconds to load a page.

8:37

All you have to do is open up your editor and go into dev. py. And where it says middleware is equal to middleware plus Django debug toolbar, we also want to get rid of the installed app Django Debug Toolbar. So I'm simply going to comment those out because I'm I'm going to want to bring them back later. Now because we're using git we could actually totally remove Both of these lines, uh, we could actually get rid of this middleware one altogether, but for the sake of reference, I'm just gonna leave it in there so that When Django debug to a bar does start to work appropriately again, that this will not be a problem. We can simply uncomment and we are good to go. Now I saved that page and you can see that I'm using Django version 2.

9:24

2. 2. I'm still using my dev settings on port 8000 and it automatically restarted for me. And I'm just going to clear manage. py run server port 8000 And let's see how fast this loads without Django debug toolbar. So this little notch over here is not going to show up. It's basically instant So it's very, very fast. So you can see the Django debug toolbar does add a lot of overhead. It is a profiling tool, and that means it's going to log all your queries, it's going to try to figure out all the templates that are being used. It's going to reverse traverse through your entire project to figure out everything that's going on to give you a detailed report.

10:09

And even with older versions of Django debug toolbar, I've seen that this can actually get very, very slow, and on some versions, I I think it was Django debug toolbar version 1. 9. Some pages would take upwards to two minutes to load, and it was so bad that I just got rid of it for a little while. It's a really nice tool to have. It's not completely necessary to be totally honest, but it is really nice to have. So when it is working, it is a beautiful tool to have. Now with all that said, I'm in my admin. There's no more alert that doesn't it doesn't tell me that I can upgrade to version 2. 5. 1, which a little side note about that, if you have upgraded to Wagtail version 2. 5 Make sure you are using 2. 5. 1. There was a bug that was fixed.

10:56

We've upgraded Django to use Django 2. 2. 2. So now we're using a more modern version of Django as well. We actually skipped over a uh a bug that was introduced in Django 2. 2, I believe it was, where when you would save a file, your your your terminal would not automatically restart. And that was sort of Well that was annoying. So we skipped right over that. That's good news. And there were some security patches in there. So uh yeah, we are good to go with this. Now I'm going to commit all this into our repo, and you'll be able to access all the changed code, which is not very much I'm also going to change the requirements. txt file and the pip file and commit those as well. So that's all there is for this video.

11:41

Thank you for tuning in. My name is Caleb Tallin. You can follow me on the social medias You can also join our Wagtail Slack at Wagtail. io slash Slack, or you can find the rest of these videos at Wagtail. io slash course. It will bring you straight to the YouTube playlist so you can access all of the other videos pretty much instantly. And don't forget, you can always share, comment, and I would love if you would subscribe, but if you don't, I just hope you got some value from this video. Thanks for tuning in and I'll see you around next time.

Questions this talk answers

How do I upgrade Wagtail from 2.4 to 2.5.1?

Inside the project environment, run `pip install --upgrade wagtail`, or pin the exact release with `pip install wagtail==2.5.1`. The speaker recommends using 2.5.1 because it includes a bug fix.

Discussed at 2:18

How do I upgrade Django in a Wagtail project?

Use pip to install the desired version, such as `pip install Django==2.2.2`, then run the project and apply database changes with `python manage.py migrate`.

Discussed at 3:04

How can I fix Django Debug Toolbar errors after upgrading Django?

The talk tests a newer alpha release, Django Debug Toolbar 2.0a1, which works locally but makes requests extremely slow. The practical fix shown is to disable the toolbar until a suitable release is available.

Discussed at 7:52

How do I disable Django Debug Toolbar in Django development settings?

In `dev.py`, comment out both the Django Debug Toolbar entry in `MIDDLEWARE` and its entry in `INSTALLED_APPS`. They can be uncommented later when the toolbar works properly again.

Discussed at 8:37

Why does Django Debug Toolbar make pages load slowly?

It profiles the request by logging queries, inspecting templates, and traversing the project to produce a detailed report. That profiling can add substantial overhead, with some releases making pages take many seconds or even minutes to load.

Discussed at 9:24

Note: We understand that names change, people change, and bodies change. We respect each individual's journey and privacy. If you have any concerns about a video or need us to remove content, please don't hesitate to contact us. We will handle your request with care and promptly address any issues.

More videos from Wagtail CMS