From 4cdb6b2959f6d13417c48781d53c4e7e685934e7 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Stephan=20Gro=C3=9F?= Date: Mon, 4 Mar 2013 13:53:39 +0100 Subject: [PATCH 1/6] Fix authtoken migration --- docs/api-guide/settings.md | 12 ++++++++++++ docs/topics/release-notes.md | 1 + rest_framework/authtoken/migrations/0001_initial.py | 6 +++++- rest_framework/settings.py | 3 +++ 4 files changed, 21 insertions(+), 1 deletion(-) diff --git a/docs/api-guide/settings.md b/docs/api-guide/settings.md index e103fbab4..0ecb1d2d6 100644 --- a/docs/api-guide/settings.md +++ b/docs/api-guide/settings.md @@ -174,4 +174,16 @@ The name of a parameter in the URL conf that may be used to provide a format suf Default: `'format'` +## REQUIRED_MIGRATIONS + +This is a list of required migrations which are needed by the authtoken migration. + +E.g. + + ( + ('users', '0001_initial'), + ) + +Default: `'()'` + [cite]: http://www.python.org/dev/peps/pep-0020/ diff --git a/docs/topics/release-notes.md b/docs/topics/release-notes.md index 43499c9a9..f6ef2c18f 100644 --- a/docs/topics/release-notes.md +++ b/docs/topics/release-notes.md @@ -45,6 +45,7 @@ You can determine your currently installed version using `pip freeze`: * Request authentication is no longer lazily evaluated, instead authentication is always run, which results in more consistent, obvious behavior. Eg. Supplying bad auth credentials will now always return an error response, even if no permissions are set on the view. * Bugfix for serializer data being uncacheable with pickle protocol 0. * Bugfixes for model field validation edge-cases. +* Bugfix for authtoken migration while using a custom user model. ### 2.2.1 diff --git a/rest_framework/authtoken/migrations/0001_initial.py b/rest_framework/authtoken/migrations/0001_initial.py index f4e052e48..b0c81bf19 100644 --- a/rest_framework/authtoken/migrations/0001_initial.py +++ b/rest_framework/authtoken/migrations/0001_initial.py @@ -4,6 +4,8 @@ from south.db import db from south.v2 import SchemaMigration from django.db import models +from rest_framework.settings import api_settings + try: from django.contrib.auth import get_user_model @@ -15,6 +17,8 @@ else: class Migration(SchemaMigration): + depends_on = api_settings.REQUIRED_MIGRATIONS + def forwards(self, orm): # Adding model 'Token' db.create_table('authtoken_token', ( @@ -45,7 +49,7 @@ class Migration(SchemaMigration): 'name': ('django.db.models.fields.CharField', [], {'max_length': '50'}) }, "%s.%s" % (User._meta.app_label, User._meta.module_name): { - 'Meta': {'object_name': 'User'}, + 'Meta': {'object_name': User._meta.module_name}, 'date_joined': ('django.db.models.fields.DateTimeField', [], {'default': 'datetime.datetime.now'}), 'email': ('django.db.models.fields.EmailField', [], {'max_length': '75', 'blank': 'True'}), 'first_name': ('django.db.models.fields.CharField', [], {'max_length': '30', 'blank': 'True'}), diff --git a/rest_framework/settings.py b/rest_framework/settings.py index b7aa0bbe0..319122150 100644 --- a/rest_framework/settings.py +++ b/rest_framework/settings.py @@ -76,6 +76,9 @@ DEFAULTS = { 'URL_FORMAT_OVERRIDE': 'format', 'FORMAT_SUFFIX_KWARG': 'format', + + # Authtoken + 'REQUIRED_MIGRATIONS': (), } From d6391359f5cf4be394cf5785edab882f28cb225a Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Stephan=20Gro=C3=9F?= Date: Mon, 4 Mar 2013 14:04:03 +0100 Subject: [PATCH 2/6] Fix fix migrate authtoken --- docs/api-guide/settings.md | 12 ------------ rest_framework/authtoken/migrations/0001_initial.py | 2 -- rest_framework/settings.py | 3 --- 3 files changed, 17 deletions(-) diff --git a/docs/api-guide/settings.md b/docs/api-guide/settings.md index 0ecb1d2d6..e103fbab4 100644 --- a/docs/api-guide/settings.md +++ b/docs/api-guide/settings.md @@ -174,16 +174,4 @@ The name of a parameter in the URL conf that may be used to provide a format suf Default: `'format'` -## REQUIRED_MIGRATIONS - -This is a list of required migrations which are needed by the authtoken migration. - -E.g. - - ( - ('users', '0001_initial'), - ) - -Default: `'()'` - [cite]: http://www.python.org/dev/peps/pep-0020/ diff --git a/rest_framework/authtoken/migrations/0001_initial.py b/rest_framework/authtoken/migrations/0001_initial.py index b0c81bf19..b7c563afd 100644 --- a/rest_framework/authtoken/migrations/0001_initial.py +++ b/rest_framework/authtoken/migrations/0001_initial.py @@ -17,8 +17,6 @@ else: class Migration(SchemaMigration): - depends_on = api_settings.REQUIRED_MIGRATIONS - def forwards(self, orm): # Adding model 'Token' db.create_table('authtoken_token', ( diff --git a/rest_framework/settings.py b/rest_framework/settings.py index 319122150..b7aa0bbe0 100644 --- a/rest_framework/settings.py +++ b/rest_framework/settings.py @@ -76,9 +76,6 @@ DEFAULTS = { 'URL_FORMAT_OVERRIDE': 'format', 'FORMAT_SUFFIX_KWARG': 'format', - - # Authtoken - 'REQUIRED_MIGRATIONS': (), } From b4c9b68c965c8e07712bf6d173abe4d1e59f8728 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Stephan=20Gro=C3=9F?= Date: Mon, 4 Mar 2013 14:09:59 +0100 Subject: [PATCH 3/6] Add note for using authtoken with custom django user model and south --- docs/api-guide/authentication.md | 2 ++ 1 file changed, 2 insertions(+) diff --git a/docs/api-guide/authentication.md b/docs/api-guide/authentication.md index fae86386d..80d29ff47 100644 --- a/docs/api-guide/authentication.md +++ b/docs/api-guide/authentication.md @@ -169,6 +169,8 @@ The `obtain_auth_token` view will return a JSON response when valid `username` a Note that the default `obtain_auth_token` view explicitly uses JSON requests and responses, rather than using default renderer and parser classes in your settings. If you need a customized version of the `obtain_auth_token` view, you can do so by overriding the `ObtainAuthToken` view class, and using that in your url conf instead. +**Note:** If you are using `rest_framework.authtoken` with a custom Django user model and South. you have to insert a `needed_by = (('authtoken', '0001_initial'),)` to your user migration. + ## SessionAuthentication This authentication scheme uses Django's default session backend for authentication. Session authentication is appropriate for AJAX clients that are running in the same session context as your website. From 7db2332c4006cd2c79b0ad002bcd9e15f7075ca6 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Stephan=20Gro=C3=9F?= Date: Mon, 4 Mar 2013 14:11:05 +0100 Subject: [PATCH 4/6] Update release docs --- docs/topics/release-notes.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/docs/topics/release-notes.md b/docs/topics/release-notes.md index f6ef2c18f..352b16307 100644 --- a/docs/topics/release-notes.md +++ b/docs/topics/release-notes.md @@ -45,7 +45,7 @@ You can determine your currently installed version using `pip freeze`: * Request authentication is no longer lazily evaluated, instead authentication is always run, which results in more consistent, obvious behavior. Eg. Supplying bad auth credentials will now always return an error response, even if no permissions are set on the view. * Bugfix for serializer data being uncacheable with pickle protocol 0. * Bugfixes for model field validation edge-cases. -* Bugfix for authtoken migration while using a custom user model. +* Bugfix for authtoken migration while using a custom user model and south. ### 2.2.1 From 27175c2cf50022af5c4683ba0283506c5f9a5fc6 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Stephan=20Gro=C3=9F?= Date: Mon, 4 Mar 2013 17:04:55 +0100 Subject: [PATCH 5/6] Update migration --- rest_framework/authtoken/migrations/0001_initial.py | 12 ------------ 1 file changed, 12 deletions(-) diff --git a/rest_framework/authtoken/migrations/0001_initial.py b/rest_framework/authtoken/migrations/0001_initial.py index b7c563afd..21b35f151 100644 --- a/rest_framework/authtoken/migrations/0001_initial.py +++ b/rest_framework/authtoken/migrations/0001_initial.py @@ -48,19 +48,7 @@ class Migration(SchemaMigration): }, "%s.%s" % (User._meta.app_label, User._meta.module_name): { 'Meta': {'object_name': User._meta.module_name}, - 'date_joined': ('django.db.models.fields.DateTimeField', [], {'default': 'datetime.datetime.now'}), - 'email': ('django.db.models.fields.EmailField', [], {'max_length': '75', 'blank': 'True'}), - 'first_name': ('django.db.models.fields.CharField', [], {'max_length': '30', 'blank': 'True'}), - 'groups': ('django.db.models.fields.related.ManyToManyField', [], {'to': "orm['auth.Group']", 'symmetrical': 'False', 'blank': 'True'}), 'id': ('django.db.models.fields.AutoField', [], {'primary_key': 'True'}), - 'is_active': ('django.db.models.fields.BooleanField', [], {'default': 'True'}), - 'is_staff': ('django.db.models.fields.BooleanField', [], {'default': 'False'}), - 'is_superuser': ('django.db.models.fields.BooleanField', [], {'default': 'False'}), - 'last_login': ('django.db.models.fields.DateTimeField', [], {'default': 'datetime.datetime.now'}), - 'last_name': ('django.db.models.fields.CharField', [], {'max_length': '30', 'blank': 'True'}), - 'password': ('django.db.models.fields.CharField', [], {'max_length': '128'}), - 'user_permissions': ('django.db.models.fields.related.ManyToManyField', [], {'to': "orm['auth.Permission']", 'symmetrical': 'False', 'blank': 'True'}), - 'username': ('django.db.models.fields.CharField', [], {'unique': 'True', 'max_length': '30'}) }, 'authtoken.token': { 'Meta': {'object_name': 'Token'}, From 214e201ff87baea9f13ae3dccd9f905484de68ef Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Stephan=20Gro=C3=9F?= Date: Mon, 4 Mar 2013 17:12:02 +0100 Subject: [PATCH 6/6] Update migration --- rest_framework/authtoken/migrations/0001_initial.py | 1 - 1 file changed, 1 deletion(-) diff --git a/rest_framework/authtoken/migrations/0001_initial.py b/rest_framework/authtoken/migrations/0001_initial.py index 21b35f151..d5965e404 100644 --- a/rest_framework/authtoken/migrations/0001_initial.py +++ b/rest_framework/authtoken/migrations/0001_initial.py @@ -48,7 +48,6 @@ class Migration(SchemaMigration): }, "%s.%s" % (User._meta.app_label, User._meta.module_name): { 'Meta': {'object_name': User._meta.module_name}, - 'id': ('django.db.models.fields.AutoField', [], {'primary_key': 'True'}), }, 'authtoken.token': { 'Meta': {'object_name': 'Token'},