#28159: Using InlineFormset.save_as_new crashes in Django 1.11
-------------------------------------+-------------------------------------
     Reporter:  Alexander Kavanaugh  |                    Owner:  nobody
         Type:  Bug                  |                   Status:  new
    Component:  Forms                |                  Version:  1.11
     Severity:  Release blocker      |               Resolution:
     Keywords:                       |             Triage Stage:  Accepted
  inlineformset,save_as_new          |
    Has patch:  1                    |      Needs documentation:  0
  Needs tests:  1                    |  Patch needs improvement:  0
Easy pickings:  0                    |                    UI/UX:  0
-------------------------------------+-------------------------------------
Changes (by Tim Graham):

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


Old description:

> Django 1.11 now marks multipart POST data as immutable [(Release notes
> section)](https://docs.djangoproject.com/en/1.11/releases/1.11/#miscellaneous).
> This causes an issue with the private ``save_as_new`` feature in
> InlineFormsets: the set code in the conditional block
> [here](https://github.com/django/django/blob/master/django/forms/models.py#L886)
> now throws an AttributeError because the data it's attempting to change
> is marked as immutable.
>
> To restore previous behavior, this pull request turns off the
> immutability flag on the form data while the save_as_new functionality
> runs and turns immutability back on when the mutation code is complete.
>
> Note that the mutable flag isn't set if there is no data, hence the
> ``hasattr`` code.
>
> PR: https://github.com/django/django/pull/8448

New description:

 Django 1.11 marks multipart POST data as immutable:
 4a246a02bdcbc13b15480c014f51cb0682af7c1e (#17235) . This causes an issue
 with the private `save_as_new` feature in InlineFormsets: the set code in
 the conditional block in
 
[https://github.com/django/django/blob/05098fa4494e66e1d3750d7f4821f7b3114693b9/django/forms/models.py#L886
 BaseInlineFormSet._construct_form()] now raises `AttributeError` because
 the data it's attempting to change is marked as immutable.

 To restore previous behavior, [https://github.com/django/django/pull/8448
 this pull request] turns off the immutability flag on the form data while
 the save_as_new functionality runs and turns immutability back on when the
 mutation code is complete.

 Note that the mutable flag isn't set if there is no data, hence the
 `hasattr` code.

--

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

-- 
You received this message because you are subscribed to the Google Groups 
"Django updates" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to [email protected].
To post to this group, send email to [email protected].
To view this discussion on the web visit 
https://groups.google.com/d/msgid/django-updates/064.486e1e874eff23fdafcd14a7502c8224%40djangoproject.com.
For more options, visit https://groups.google.com/d/optout.

Reply via email to