[Django] #21615: contenttypes/generic.py regression from 1.6 --> 1.6.1

5 views
Skip to first unread message

Django

unread,
Dec 13, 2013, 9:18:48 PM12/13/13
to django-...@googlegroups.com
#21615: contenttypes/generic.py regression from 1.6 --> 1.6.1
--------------------------------------+----------------------------
Reporter: kz26 | Owner: nobody
Type: Bug | Status: new
Component: contrib.contenttypes | Version: 1.6
Severity: Normal | Keywords: form modelform
Triage Stage: Unreviewed | Has patch: 0
Easy pickings: 0 | UI/UX: 0
--------------------------------------+----------------------------
Model:

{{{
class Post(models.Model):
class Meta:
ordering = ['-modified']
eid = models.CharField(max_length=40, blank=True, db_index=True)
user = models.ForeignKey(settings.AUTH_USER_MODEL)
school = models.ForeignKey(School)
title = models.CharField(max_length=255,
validators=[MinLengthValidator(5)])
category = models.CharField(max_length=3,
choices=ORIENTATION_CHOICES)
affiliation = models.CharField(max_length=3,
choices=AFFILIATION_CHOICES)
age = models.CharField(max_length=255, help_text='Use a comma-
separated list to enter more than one age, e.g. for couples and groups')
external_replies = models.BooleanField(default=True)
message = models.TextField()
date = models.DateTimeField(default=timezone.now)
modified = models.DateTimeField(null=True, blank=True)
deleted = models.BooleanField(default=False)
expiration = models.DateTimeField()
replied = models.ManyToManyField(settings.AUTH_USER_MODEL,
blank=True, related_name="+")
files = generic.GenericRelation(UploadedFile)
}}}

ModelForm:

{{{
class PostForm(forms.ModelForm):
class Meta:
model = Post
fields = ('title', 'affiliation', 'category', 'age',
'external_replies', 'message', 'files')

message = HTMLField(widget=CKEditorArea)
files = forms.FileField(required=False,
validators=[validate_filesize, validate_mm_filetype])
}}}

View:

{{{
class EditPost(UpdateView):
model = Post
form_class = PostForm
template_name = "posts/new_edit_post.html"

@transaction.atomic
def form_valid(self, form):
response = super(EditPost, self).form_valid(form)
for f in
self.request.FILES.getlist('files')[:settings.MAX_UPLOAD_COUNT -
self.object.files.all().count()]:
UploadedFile.objects.create(content_object=self.object, file=f)
self.object.modified = timezone.now()
self.object.save()
return response
}}}

The edit view works fine in Django 1.6, but after upgrading to 1.6.1 I get
the following stacktrace:

{{{
Traceback (most recent call last):

File "/home/twosb/lib/python2.7/site-
packages/django/core/handlers/base.py", line 114, in get_response
response = wrapped_callback(request, *callback_args,
**callback_kwargs)

File "/home/twosb/lib/python2.7/site-
packages/django/views/generic/base.py", line 69, in view
return self.dispatch(request, *args, **kwargs)

File "/home/twosb/lib/python2.7/site-
packages/django/utils/decorators.py", line 29, in _wrapper
return bound_func(*args, **kwargs)

File "/home/twosb/lib/python2.7/site-
packages/django/contrib/auth/decorators.py", line 22, in _wrapped_view
return view_func(request, *args, **kwargs)

File "/home/twosb/lib/python2.7/site-
packages/django/utils/decorators.py", line 25, in bound_func
return func(self, *args2, **kwargs2)

File "/home/twosb/app/twosb/posts/views.py", line 141, in dispatch
response = super(EditPost, self).dispatch(request, *args, **kwargs)

File "/home/twosb/lib/python2.7/site-
packages/django/views/generic/base.py", line 87, in dispatch
return handler(request, *args, **kwargs)

File "/home/twosb/lib/python2.7/site-
packages/django/views/generic/edit.py", line 228, in post
return super(BaseUpdateView, self).post(request, *args, **kwargs)

File "/home/twosb/lib/python2.7/site-
packages/django/views/generic/edit.py", line 171, in post
return self.form_valid(form)

File "/home/twosb/lib/python2.7/site-packages/django/db/transaction.py",
line 339, in inner
return func(*args, **kwargs)

File "/home/twosb/app/twosb/posts/views.py", line 148, in form_valid
response = super(EditPost, self).form_valid(form)

File "/home/twosb/lib/python2.7/site-
packages/django/views/generic/edit.py", line 147, in form_valid
self.object = form.save()

File "/home/twosb/lib/python2.7/site-packages/django/forms/models.py",
line 446, in save
construct=False)

File "/home/twosb/lib/python2.7/site-packages/django/forms/models.py",
line 100, in save_instance
save_m2m()

File "/home/twosb/lib/python2.7/site-packages/django/forms/models.py",
line 96, in save_m2m
f.save_form_data(instance, cleaned_data[f.name])

File "/home/twosb/lib/python2.7/site-
packages/django/db/models/fields/__init__.py", line 516, in save_form_data
setattr(instance, self.name, data)

File "/home/twosb/lib/python2.7/site-
packages/django/contrib/contenttypes/generic.py", line 292, in __set__
for obj in value:

TypeError: 'NoneType' object is not iterable
}}}

--
Ticket URL: <https://code.djangoproject.com/ticket/21615>
Django <https://code.djangoproject.com/>
The Web framework for perfectionists with deadlines.

Django

unread,
Dec 17, 2013, 6:12:26 PM12/17/13
to django-...@googlegroups.com
#21615: contenttypes/generic.py regression from 1.6 --> 1.6.1
--------------------------------------+------------------------------------

Reporter: kz26 | Owner: nobody
Type: Bug | Status: new
Component: contrib.contenttypes | Version: 1.6
Severity: Release blocker | Resolution:
Keywords: form modelform | Triage Stage: Accepted
Has patch: 0 | Needs documentation: 0
Needs tests: 0 | Patch needs improvement: 0

Easy pickings: 0 | UI/UX: 0
--------------------------------------+------------------------------------
Changes (by timo):

* needs_better_patch: => 0
* needs_docs: => 0
* severity: Normal => Release blocker
* needs_tests: => 0
* stage: Unreviewed => Accepted


Comment:

If you could construct a more minimal example to reproduce the problem
(preferably in the form a test for Django's test suite) that will help us
fix this.

--
Ticket URL: <https://code.djangoproject.com/ticket/21615#comment:1>

Django

unread,
Dec 20, 2013, 4:19:29 AM12/20/13
to django-...@googlegroups.com
#21615: contenttypes/generic.py regression from 1.6 --> 1.6.1
--------------------------------------+------------------------------------

Reporter: kz26 | Owner: nobody
Type: Bug | Status: new
Component: contrib.contenttypes | Version: 1.6
Severity: Release blocker | Resolution:
Keywords: form modelform | Triage Stage: Accepted
Has patch: 0 | Needs documentation: 0
Needs tests: 0 | Patch needs improvement: 0

Easy pickings: 0 | UI/UX: 0
--------------------------------------+------------------------------------

Comment (by akaariai):

I am pretty sure I am responsible for the regression. So, I'll take a
look.

--
Ticket URL: <https://code.djangoproject.com/ticket/21615#comment:2>

Django

unread,
Dec 28, 2013, 10:44:21 AM12/28/13
to django-...@googlegroups.com
#21615: contenttypes/generic.py regression from 1.6 --> 1.6.1
--------------------------------------+------------------------------------
Reporter: kz26 | Owner: nobody
Type: Bug | Status: closed
Component: contrib.contenttypes | Version: 1.6
Severity: Release blocker | Resolution: wontfix

Keywords: form modelform | Triage Stage: Accepted
Has patch: 0 | Needs documentation: 0
Needs tests: 0 | Patch needs improvement: 0

Easy pickings: 0 | UI/UX: 0
--------------------------------------+------------------------------------
Changes (by akaariai):

* status: new => closed
* resolution: => wontfix


Comment:

To me it seems this works exactly like it did in 1.5.

The idea here is that if the form has a field with the same name as
GenericRelation's name in the model, then that form field will be used to
supply data for the GenericRelation in saving. This didn't work in 1.6,
and at least Mezzanine used heavily this feature. We can't have it both
ways, and the fix for 1.6.1 was considered a regression fix. Or in other
words, the way it worked in 1.6.0 wasn't considered correct.

A workaround is to rename the 'files', either in the form or the model.
Doing this for the form is likely easier.

If there is in fact a change from the way this worked in 1.5 please
reopen.

--
Ticket URL: <https://code.djangoproject.com/ticket/21615#comment:3>

Reply all
Reply to author
Forward
0 new messages