1 of 29

1

Django 1.8 to 1.11: Tips for an (almost) painless upgrade

Ali Tycast

July 17, 2019

The Black Tux + PyLadies + LA Django

2 of 29

Hello!

I’m Ali -

  • Back End Developer
  • Python, Ruby
  • Business Operations team at The Black Tux

2

3 of 29

Why did we upgrade from Django 1.8 to 1.11?

4 of 29

We want to be on a supported version

We were missing out on:

  • Security updates
  • Bug fixes

  • Current version is 2.2.3
  • 1.11 is the latest release on Python 2.7

4

5 of 29

Make it a point to do something everyday that you don't want to do.

  • Mark Twain

5

6 of 29

How’d we do it?

6

7 of 29

Read the release notes

  • Deprecated features
  • Backwards incompatibility
  • Database changes

7

Example:

In model forms, CharField with null=True now saves NULL for blank values instead of empty strings.

8 of 29

Upgrade dependencies

  • django-debug-toolbar==1.8
  • django-nose==1.4.6
  • django-object-actions==1.0.0
  • sorl-thumbnail==12.5.0
  • django-concurrency==1.4
  • django-cors-headers==2.4.1
  • django-extensions==1.9.9
  • django-lionheart-helpers==3.0.4
  • django-localflavor==1.6
  • django-redis==4.8.0
  • six==1.12.0
  • djangorestframework==3.6.4

8

9 of 29

Update our imports

  • All models need to be defined inside an installed application.

  • Not possible to import them before their application is loaded.

  • Not possible to import models inside the root package of an application.

9

10 of 29

Update our imports

10

11 of 29

Fix deprecation warnings

11

12 of 29

Fix deprecation warnings

12

13 of 29

A lot of other random fixes...

13

14 of 29

How’d we release this?

14

15 of 29

You may have to fight a battle more than once to win it.

  • Margaret Thatcher

15

16 of 29

Multiple releases

  • Package upgrades

  • Import changes

  • Runtime warnings (timezones)

  • Everything else

16

17 of 29

Now we can talk about problems...

17

😭

18 of 29

Static assets

  • We committed Django admin static files to our repo years ago
    • Django admin files conflicted with what we had committed when we upgraded to 1.11

  • We didn’t realize django admin magic was generating static assets, so we had removed release steps to upload these 1.11 assets to S3

  • Staging and prod used different packages to upload our static assets to S3, which made issues difficult to debug

18

19 of 29

What did we learn?

20 of 29

Don’t avoid upgrading!

  • You need to do it. Just do it.

  • Updating code is harder the longer the version distance is

  • Upgrading as each new Django release is available makes future upgrades less painful by keeping your code base up to date.

20

21 of 29

Know your app

  • Django uses a lot of “magic” - make sure you know when you’re using it, how you're using it, and why

  • If you know the “when, how and why”, you can catch breaking changes before they happen

21

22 of 29

Follow convention… or don’t

  • It’s okay to deviate from convention..

  • But do it for a reason. And document it.

22

23 of 29

Tests

  • Write tests!

  • Even ones you don’t think you need!
    • Django admin

  • Run tests!

23

24 of 29

Keep your environments in sync

  • Differences between environments (i.e.dev, staging, production) don't seem like a big deal... until they are

  • The fact that we used different Static Asset backends on staging and prod really hurt us

  • We also had bugs in our dev and staging environments that didn’t exist on prod… ouch.

24

25 of 29

Pay attention to warnings

  • Deprecation warnings (or any warnings) are there for a reason

  • Keep up with them and save yourself a lot of time… future you will be very happy!

25

26 of 29

Lean on your team

  • It helps everyone to ask for help.

  • The more people involved, the more people who will learn and have a deeper understanding of your new version!

26

27 of 29

Commit

  • This is a real project, treat it as such

  • Timelines

  • Deadlines

  • This is how you get the support of your team!

27

28 of 29

28

29 of 29

29

Questions?

Thank you!