Mercurial > public > pelican-blog
comparison content/Coding/027-upgrading-django1.6.rst @ 4:7ce6393e6d30
Adding converted blog posts from old blog.
author | Brian Neal <bgneal@gmail.com> |
---|---|
date | Thu, 30 Jan 2014 21:45:03 -0600 |
parents | |
children | 49bebfa6f9d3 |
comparison
equal
deleted
inserted
replaced
3:c3115da3ff73 | 4:7ce6393e6d30 |
---|---|
1 Upgrading to Django 1.6 | |
2 ####################### | |
3 | |
4 :date: 2013-12-29 18:00 | |
5 :tags: Django | |
6 :slug: upgrading-to-django-1.6 | |
7 :author: Brian Neal | |
8 | |
9 Getting started | |
10 =============== | |
11 | |
12 `Django`_ 1.6 came out recently, which was soon followed by 1.6.1, and it looks | |
13 like 1.6.2 is on the way. I finally got around to upgrading two of my largest | |
14 sites. I thought I would make a list of what I changed at a high level for my | |
15 own reference. Perhaps someone else may find it useful as well. | |
16 | |
17 In any event, I highly recommend you read the excellent `release notes`_ and | |
18 `deprecation timeline`_. The changes in 1.6 didn't seem groundbreaking, but | |
19 they were numerous. I spent a lot of time reading through the notes and trying | |
20 to decide if the issues affected me or not. | |
21 | |
22 I recommend you run with warnings turned on:: | |
23 | |
24 $ python -Wall manage.py runserver | |
25 | |
26 This will help you flag down issues in your code. If you aren't sure where | |
27 a warning is coming from, you can turn warnings into exceptions and get | |
28 a traceback (see the Python docs on the warnings_ library). Another trick is to | |
29 put a pdb_ breakpoint in the Django code before or after the warning, then you | |
30 can examine the call stack with the ``w`` command. | |
31 | |
32 Upgrade Issues | |
33 ============== | |
34 | |
35 Here are the issues that I ran into. Of course you may have a very different | |
36 experience depending on what features of Django you used and the details of | |
37 your site. | |
38 | |
39 #. The location of the ``XViewMiddleware`` changed. I had to update my | |
40 ``MIDDLEWARE_CLASSES`` setting as a result. | |
41 #. Various ``get_query_set`` to ``get_queryset`` changes. The Django developers | |
42 have ironed out some naming inconsistencies in method names on both model | |
43 managers and ``ModelAdmin`` classes. | |
44 #. In template / form processing, the ``label_tag`` now includes the | |
45 ``label_suffix``. I noticed this when I saw that I had two colons on a form | |
46 field's label. | |
47 #. One very nice change that I am please to see is that Django now does test | |
48 discovery just like the unittest_ module in the standard library. To take | |
49 advantage of this I renamed all my test modules from ``view_tests.py`` to | |
50 ``test_views.py``, for example. This also let me get rid of ``import`` | |
51 statements in various ``__init__.py`` files in test subdirectories. In other | |
52 words, you no longer have to have silly lines like | |
53 ``from view_tests import *`` in your test packages' ``__init__.py`` files. | |
54 #. Django now supports database connection persistence. To take advantage of | |
55 this you need to set the CONN_MAX_AGE_ setting to a non-zero value. | |
56 #. The ``CACHE_MIDDLEWARE_ANONYMOUS_ONLY`` setting is now deprecated and can be | |
57 removed. For various reasons explained in the notes this never really worked | |
58 right anyway. | |
59 #. Updated to version 1.0 of the django-debug-toolbar_. The version I was using | |
60 would not work in Django 1.6. It is so good to see that this project is | |
61 being actively maintained again. There are several new panels and neat | |
62 features, check it out! | |
63 #. You now get a warning if you have a ``ModelForm`` without an ``exclude`` or | |
64 ``fields`` meta option. This is rather nice as I have been bit by this in | |
65 the past when a form suddenly started showing a newly added field that it | |
66 should not have. I added a ``fields`` option to a ``ModelForm`` as a result. | |
67 Unfortunately some third party applications I am using have this problem as | |
68 well. | |
69 #. The ``cycle`` tag has new XSS_ protection. To make use of it now, you have | |
70 to add a ``{% load cycle from future %}`` tag into your templates. | |
71 #. The ``django.contrib.auth`` password reset function is now using base 64 encoding of the | |
72 ``User`` primary key. The details are `here <https://docs.djangoproject.com/en/1.6/releases/1.6/#django-contrib-auth-password-reset-uses-base-64-encoding-of-user-pk>`_. This affected me | |
73 because I am using a custom password reset URL, and thus I needed to update | |
74 my URL pattern for both the new parameter name and the regular expression | |
75 for base 64. I missed this originally and I started getting 404's on my | |
76 password reset confirmation URLs. And yes, this is something I should have a | |
77 test for! | |
78 | |
79 What I didn't do | |
80 ================ | |
81 | |
82 Many of the warnings that I got came from third party modules that I have not | |
83 updated in a long time, including Celery_ and Haystack_. I am going to have to | |
84 schedule some time to update to the latest versions of these apps. Hopefully | |
85 the warnings will be fixed in the newer versions, but if not I can write | |
86 tickets or possibly submit patches / pull requests. This is the price of | |
87 progress I suppose. | |
88 | |
89 I also use a couple of smaller third party applications that seem to be no | |
90 longer maintained. These apps are now generating some warnings. I'll have to | |
91 fork them and fix these myself. Luckily these projects are on GitHub so this | |
92 should not be a problem. | |
93 | |
94 Finally I am still facing the problem of what to do about the deprecation of | |
95 the ``AUTH_PROFILE_MODULE`` and the ``get_profile`` method. This will be | |
96 removed in Django 1.7. I've been doing some more reading about this and I'm | |
97 less scared about this than I used to. I'll probably just change my profile | |
98 model to have a one-to-one relationship with the provided ``User`` model. I'll | |
99 have to do some more researching and thinking about this before Django 1.7. | |
100 | |
101 | |
102 Conclusion | |
103 ========== | |
104 | |
105 Once again the upgrade process went smoother and quicker than I thought thanks | |
106 to the excellent release notes and the Django team's use of Python warnings to | |
107 flag deprecated features. | |
108 | |
109 | |
110 .. _Django: https://www.djangoproject.com/ | |
111 .. _release notes: https://docs.djangoproject.com/en/1.6/releases/1.6/ | |
112 .. _deprecation timeline: https://docs.djangoproject.com/en/1.6/internals/deprecation/ | |
113 .. _warnings: http://docs.python.org/library/warnings.html | |
114 .. _pdb: http://docs.python.org/library/pdb.html | |
115 .. _unittest: http://docs.python.org/2/library/unittest.html | |
116 .. _CONN_MAX_AGE: https://docs.djangoproject.com/en/1.6/ref/settings/#conn-max-age | |
117 .. _XSS: http://en.wikipedia.org/wiki/Cross-site_scripting | |
118 .. _configurable user model: https://docs.djangoproject.com/en/1.5/topics/auth/customizing/#auth-custom-user | |
119 .. _django-debug-toolbar: https://pypi.python.org/pypi/django-debug-toolbar | |
120 .. _Celery: http://www.celeryproject.org/ | |
121 .. _Haystack: http://haystacksearch.org/ |