Opened 4 years ago

Closed 4 years ago

#21615 closed Bug (wontfix)

contenttypes/ regression from 1.6 --> 1.6.1

Reported by: kz26 Owned by: nobody
Component: contrib.contenttypes Version: 1.6
Severity: Release blocker Keywords: form modelform
Cc: Triage Stage: Accepted
Has patch: no Needs documentation: no
Needs tests: no Patch needs improvement: no
Easy pickings: no UI/UX: no



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(
	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)


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])


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

	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 =
		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/", line 114, in get_response
    response = wrapped_callback(request, *callback_args, **callback_kwargs)

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

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

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

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

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

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

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

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

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

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

  File "/home/twosb/lib/python2.7/site-packages/django/views/generic/", line 147, in form_valid
    self.object =

  File "/home/twosb/lib/python2.7/site-packages/django/forms/", line 446, in save

  File "/home/twosb/lib/python2.7/site-packages/django/forms/", line 100, in save_instance

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

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

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

TypeError: 'NoneType' object is not iterable

Change History (3)

comment:1 Changed 4 years ago by Tim Graham

Severity: NormalRelease blocker
Triage Stage: UnreviewedAccepted

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.

comment:2 Changed 4 years ago by Anssi Kääriäinen

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

comment:3 Changed 4 years ago by Anssi Kääriäinen

Resolution: wontfix
Status: newclosed

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.

Note: See TracTickets for help on using tickets.
Back to Top