Slide 1

Slide 1 text

DJANGO 1.6: DJANGO 1.6: THE BEST NEW FEATURES THE BEST NEW FEATURES & THE IMPORTANT CHANGES & THE IMPORTANT CHANGES presented by Julien Phalip ( ) @julienphalip SF Django Meetup — July 25th, 2013

Slide 2

Slide 2 text

WHO'S THAT? WHO'S THAT? Julien Phalip ( ) Technical director at (Previously known as Odopod) Using Django since 2007 (ver 0.96) Django core committer since 2011 @julienphalip Nurun SF

Slide 3

Slide 3 text

THE ROAD TO DJANGO 1.6... THE ROAD TO DJANGO 1.6...

Slide 4

Slide 4 text

TIMELINE TIMELINE Version Date Time since previous release 1.0 Sep 3, 2008 — 1.1 Jul 29, 2009 11 months 1.2 May 17, 2010 9.5 months 1.3 Mar 23, 2011 10 months 1.4 Mar 23, 2012 12 months 1.5 Feb 26, 2013 11 months 1.6 Late Aug, 2013 6 months

Slide 5

Slide 5 text

THE FLAGSHIP THE FLAGSHIP NEW FEATURES NEW FEATURES

Slide 6

Slide 6 text

PYTHON 3 SUPPORT PYTHON 3 SUPPORT Experimental since Django 1.5. Now officially supported, without restrictions. New Python.org will run on Django and Python 3. ( ) http://preview.python.org/

Slide 7

Slide 7 text

PORTING YOUR APPS TO PYTHON 3 PORTING YOUR APPS TO PYTHON 3 Guide in official documentation: Jacob Kaplan-Moss' Pycon talk: http://tinyurl.com/django-python3 http://tinyurl.com/jkm-pycon-python3

Slide 8

Slide 8 text

BETTER TRANSACTION BETTER TRANSACTION MANAGEMENT MANAGEMENT The old API had barely changed since 0.9x and was frustrating to work with. New API is leaner, simpler, more explicit, more correct. Easier, fine-grained rollbacks between savepoints. Easier error management.

Slide 9

Slide 9 text

WARNING: WARNING: BACKWARDS INCOMPATIBLE BACKWARDS INCOMPATIBLE Database-level a u t o c o m m i t is now turned on by default: Every SQL statement gets committed right away. Detailed upgrading instructions: For more details, see Aymeric Augustin's DjangoCon Europe talk: http://tinyurl.com/transactions-upgrade http://tinyurl.com/djangocon-eu-transactions

Slide 10

Slide 10 text

NEW HIGH-LEVEL 'ATOMIC' FUNCTION NEW HIGH-LEVEL 'ATOMIC' FUNCTION t r a n s a c t i o n . a t o m i c : Commits on success, rolls back on exceptions. Inspired from http://tinyurl.com/django-atomic https://github.com/Xof/xact

Slide 11

Slide 11 text

Can be used as decorator: Can be used as context manager: Can be nested. f r o m d j a n g o . d b i m p o r t t r a n s a c t i o n @ t r a n s a c t i o n . a t o m i c d e f v i e w f u n c ( r e q u e s t ) : # T h i s c o d e e x e c u t e s i n s i d e a t r a n s a c t i o n . d o _ s t u f f ( ) f r o m d j a n g o . d b i m p o r t t r a n s a c t i o n d e f v i e w f u n c ( r e q u e s t ) : # T h i s c o d e e x e c u t e s i n a u t o c o m m i t m o d e # ( D j a n g o ' s d e f a u l t ) . d o _ s t u f f ( ) w i t h t r a n s a c t i o n . a t o m i c ( ) : # T h i s c o d e e x e c u t e s i n s i d e a t r a n s a c t i o n . d o _ m o r e _ s t u f f ( )

Slide 12

Slide 12 text

PERSISTENT DATABASE PERSISTENT DATABASE CONNECTIONS CONNECTIONS Before: New connection opened for each HTTP request. Now: Same connection reused between requests. One connection per worker thread. New setting: C O N N _ M A X _ A G E (defaults to 0 , i.e. turned off by default) Not as powerful as or ... ... but should still drastically improve performance (See Craig Kerstiens' blog post: ) Caveat: Not extensively tested in production yet... PgBouncer PgPool http://tinyurl.com/fixing-connections

Slide 13

Slide 13 text

NEW TEST RUNNER NEW TEST RUNNER More in line with u n i t t e s t and Python standards. Saner test discovery system.

Slide 14

Slide 14 text

MORE FLEXIBILITY MORE FLEXIBILITY FOR RUNNING TESTS FOR RUNNING TESTS Before: Run all tests in an app, all tests in a certain T e s t C a s e or one test method. Now: Run all tests within a certain directory (recursively), all tests in a certain test file, or all tests in a certain T e s t C a s e , or a particular test method.

Slide 15

Slide 15 text

NO MORE OF THIS! NO MORE OF THIS! m y a p p / t e s t s / _ _ i n i t _ _ . p y : f r o m a a a a a a a i m p o r t * f r o m b b b b b b b b b i m p o r t * f r o m c c c c i m p o r t * f r o m d d d d d d d i m p o r t * f r o m e e e e e e i m p o r t * f r o m f f f i m p o r t *

Slide 16

Slide 16 text

MORE EXPLICIT MORE EXPLICIT Only run the tests you care about. Avoid running tests for third-party code (django.contrib, pip-installed apps).

Slide 17

Slide 17 text

CAVEATS CAVEATS Tests in m o d e l s . p y must be moved to a t e s t * . p y file. Doctests must be explicitly loaded: New runner enabled by default. To revert to the old behavior: http://tinyurl.com/load-doctests T E S T _ R U N N E R = ' d j a n g o . t e s t . s i m p l e . D j a n g o T e s t S u i t e R u n n e r '

Slide 18

Slide 18 text

OTHER NEW FEATURES OTHER NEW FEATURES Pillow preferred over PIL Q u e r y s e t . e a r l i e s t ( ) , . f i r s t ( ) and . l a s t ( ) Database lookups by hour, minute, second BinaryField M o d e l A d m i n . p r e s e r v e _ f i l t e r s HTML5 types for input fields (email, url, number) Admin's jQuery upgraded to 1.9.1 Multiple documentation improvements, including a And many, many small features... Many bug fixes... deployment checklist

Slide 19

Slide 19 text

BACKWARDS-INCOMPATIBLE CHANGES BACKWARDS-INCOMPATIBLE CHANGES New transactions API: New test runner enabled by default. B o o l e a n F i e l d now defaults N o n e instead of F a l s e . Whole list: Should be easy to upgrade for most people. http://tinyurl.com/transactions-incompatible http://tinyurl.com/django-1-6-incompatible

Slide 20

Slide 20 text

REMOVED FROM DJANGO REMOVED FROM DJANGO Removed contrib apps: databrowse, markup & localflavor. django.utils.text.truncate_words() and django.utils.text.truncate_html_words() removed in favor of the django.utils.text.Truncator class Detailed list of past deprecations: http://tinyurl.com/django-1-6-removed

Slide 21

Slide 21 text

FURTHER NOTES FURTHER NOTES Support for Django 1.4 (security patches) probably extended. Python 2.6 still supported in Django 1.6 but probably dropped in Django 1.7.

Slide 22

Slide 22 text

HOW CAN YOU HELP? HOW CAN YOU HELP? Test your apps against the 1.6 beta release or the 1.6.x branch on Github. any regressions or bugs in new features. Help triage in Trac. Contribution guide: Report unreviewed tickets http://tinyurl.com/django-contribute

Slide 23

Slide 23 text

CREDITS CREDITS & for letting me pick their brains while preparing this talk. for inviting me and for running the SF Django Meetup. for kindly hosting this meetup. Aymeric Augustin Carl Meyer Rudy Mutter IGT

Slide 24

Slide 24 text

THANK YOU THANK YOU FOR LISTENING! FOR LISTENING! ANY QUESTIONS...? ANY QUESTIONS...? Get in touch: @julienphalip