Opened 13 years ago

Closed 12 years ago

Last modified 12 years ago

#17663 closed Bug (fixed)

Method "save" in BaseModelFormSet is not marked as alters_data

Reported by: Alexander Ivanov Owned by: Klaas van Schelven
Component: Forms Version: dev
Severity: Normal Keywords: formset
Cc: anssi.kaariainen@…, lemaire.adrien@… Triage Stage: Accepted
Has patch: yes Needs documentation: no
Needs tests: yes Patch needs improvement: no
Easy pickings: yes UI/UX: no

Description


Attachments (1)

save.patch (380 bytes ) - added by Alexander Ivanov 13 years ago.

Download all attachments as: .zip

Change History (9)

by Alexander Ivanov, 13 years ago

Attachment: save.patch added

comment:1 by Anssi Kääriäinen, 13 years ago

Cc: anssi.kaariainen@… added
Easy pickings: set
Needs tests: set
Triage Stage: UnreviewedAccepted

Makes sense. I wonder if this kind of patch needs tests. We don't have tests for the existing .alters_data ones. Adding a test is of course easy, just check that the function's alters_data attr is True. So, my initial feeling is why not? I guess the right place is in regressiontests/model_forms_regress/tests.py

comment:2 by Adrien Lemaire, 13 years ago

Owner: changed from nobody to Adrien Lemaire

This patch is not good, no path is given to the models.py. Notice 222 models.py exist in the project
(find . -name "models.py"|wc). Anyways, I found it after a grep, will now write the test.

comment:3 by Adrien Lemaire, 13 years ago

Cc: lemaire.adrien@… added

@akaariai, tests for alters_data are in regressiontests/templates/callables.py

EDIT: I don't think we need alters_data for BaseModelFormSet.save(). This function will call each form.save(), and BaseModelForm.save() already have this alters_data = True.

I went through the formset fields with ipdb, and couldn't find a sensitive function.

Last edited 13 years ago by Adrien Lemaire (previous) (diff)

in reply to:  3 comment:4 by Klaas van Schelven, 12 years ago

Owner: changed from Adrien Lemaire to Klaas van Schelven
Status: newassigned

Replying to Fandekasp:

@akaariai, tests for alters_data are in regressiontests/templates/callables.py

EDIT: I don't think we need alters_data for BaseModelFormSet.save(). This function will call each form.save(), and BaseModelForm.save() already have this alters_data = True.

I went through the formset fields with ipdb, and couldn't find a sensitive function.

AFAIK the alters_data = True attribute does not "magically" bubble up through used method calls (like an exception would). I.e. if you create a method on the formset that calls other methods with alters_data = True, the former does not automatically have the correct value for alters_data. In other words, this is a perfectly valid concern.

>>> from django.forms.models import modelformset_factory
>>> MyFormSet = modelformset_factory(MyModel)
>>> fs = MyFormSet()
>>> fs.save.alter_data
Traceback (most recent call last):
  File "<console>", line 1, in <module>
AttributeError: 'function' object has no attribute 'alters_data'

comment:5 by Klaas van Schelven, 12 years ago

Just adding to this to proof that the regular case (ModelForm) does work as expected:

>>> class MyModelForm(ModelForm):
...     class Meta:
...         model = MyModel
...
>>> MyModelForm().save.alters_data
True

in reply to:  1 comment:6 by Klaas van Schelven, 12 years ago

Replying to akaariai:

Makes sense. I wonder if this kind of patch needs tests. We don't have tests for the existing .alters_data ones. Adding a test is of course easy, just check that the function's alters_data attr is True. So, my initial feeling is why not? I guess the right place is in regressiontests/model_forms_regress/tests.py

I've created a pull request for this (with the correct file location).
https://github.com/django/django/pull/750

As mentioned above, and in line with the current state of the tests, I've not added tests. I have, however, ran the existing tests and no new failures are caused by this patch.

comment:7 by Klaas van Schelven <klaas@…>, 12 years ago

Resolution: fixed
Status: assignedclosed

In 91c947066408d496f8990ba90fbf2c4d1d80f63f:

Method "save" in BaseModelFormSet is marked as alters_data

Fixes #17663

comment:8 by Aymeric Augustin <aymeric.augustin@…>, 12 years ago

In 7acabbb9800de4492c0ee612a8a0aa784eb07f49:

Merge pull request #750 from vanschelven/master

Fixed #17663 -- Marked BaseModelFormSet.save as alters_data.

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