#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)
Change History (9)
by , 14 years ago
| Attachment: | save.patch added |
|---|
follow-up: 6 comment:1 by , 14 years ago
| Cc: | added |
|---|---|
| Easy pickings: | set |
| Needs tests: | set |
| Triage Stage: | Unreviewed → Accepted |
comment:2 by , 14 years ago
| Owner: | changed from to |
|---|
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.
follow-up: 4 comment:3 by , 14 years ago
| Cc: | 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.
comment:4 by , 13 years ago
| Owner: | changed from to |
|---|---|
| Status: | new → assigned |
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 eachform.save(), andBaseModelForm.save()already have thisalters_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 , 13 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
comment:6 by , 13 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 , 13 years ago
| Resolution: | → fixed |
|---|---|
| Status: | assigned → closed |
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