New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Fixed #14642 -- Fixed generic inline formsets crash when using save_as_new=True. #9385
Conversation
10d1eed
to
9f7a524
Compare
docs/releases/2.1.txt
Outdated
@@ -35,6 +35,8 @@ Minor features | |||
* :attr:`.ModelAdmin.search_fields` now accepts any lookup such as | |||
``field__exact``. | |||
|
|||
* Generic inlines now work correctly with "save as new". |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
A release note isn't needed as this is a bug fix, not a feature.
tests/generic_inline_admin/tests.py
Outdated
self.assertEqual(Media.objects.get(pk=self.mp3_media_pk).url, new_mp3_url) | ||
self.assertEqual(Media.objects.get(pk=self.png_media_pk).url, new_png_url) | ||
|
||
def test_basic_edit_POST_as_new(self): |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think the test belongs at the form layer (rather than admin) as that's the code that's fixed.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I added another test similar to the one for modelformset_factory
. save_as_new
isn't actually documented anywhere for forms though, it's only used by the admin.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Did you forget to commit that test?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Looks like I lost it in git, but I have fished it out again.
9f7a524
to
a4f61a1
Compare
f611f7d
to
2696416
Compare
tests/generic_inline_admin/tests.py
Outdated
|
||
def test_basic_edit_POST_as_new(self): | ||
""" | ||
A smoke test to ensure POST on edit_view works. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
If this needs a docstring, it should probably say something to differentiate this from the above test.
I know you copied this from the other test's comment, but I'm not sure "smoke test" is a useful description of what this test is for.
2696416
to
9093e9b
Compare
tests/generic_relations/tests.py
Outdated
'generic_relations-taggeditem-content_type-object_id-TOTAL_FORMS': '3', | ||
'generic_relations-taggeditem-content_type-object_id-INITIAL_FORMS': '2', | ||
'generic_relations-taggeditem-content_type-object_id-MAX_NUM_FORMS': '', | ||
'generic_relations-taggeditem-content_type-object_id-0-id': '1', |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The test fails on MySQL/PostgreSQL. Hardcoded id values might be the problem.
tests/generic_relations/tests.py
Outdated
quartz = Mineral.objects.create(name="Quartz", hardness=7) | ||
GenericFormSet = generic_inlineformset_factory(TaggedItem, extra=1) | ||
|
||
# An immutable QueryDict simulates request.POST. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think a plain dict should be fine here. The QueryDict
approach was because of a different issue (362fba8).
tests/generic_relations/tests.py
Outdated
@@ -513,6 +514,55 @@ def test_subclasses_with_parent_gen_rel(self): | |||
TaggedItem.objects.create(content_object=bear, tag='orange') | |||
self.assertEqual(Carrot.objects.get(tags__tag='orange'), bear) | |||
|
|||
def test_generic_inline_formsets_initial_count(self): | |||
""" | |||
Test for initial form count considering save_as_new. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Docstrings should state the expected behavior and omit prefixes like "Tests for" since all tests test things.
tests/generic_relations/tests.py
Outdated
@@ -513,6 +514,55 @@ def test_subclasses_with_parent_gen_rel(self): | |||
TaggedItem.objects.create(content_object=bear, tag='orange') | |||
self.assertEqual(Carrot.objects.get(tags__tag='orange'), bear) | |||
|
|||
def test_generic_inline_formsets_initial_count(self): |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Please move these tests to test_forms.py
following bcadabe.
tests/generic_relations/tests.py
Outdated
""" | ||
Test for initial form count considering save_as_new. | ||
""" | ||
quartz = Mineral.objects.create(name="Quartz", hardness=7) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Use single quotes throughout, please.
tests/generic_inline_admin/tests.py
Outdated
@@ -72,24 +72,58 @@ def test_basic_add_POST(self): | |||
|
|||
def test_basic_edit_POST(self): | |||
""" | |||
A smoke test to ensure POST on edit_view works. | |||
A test to ensure POST on edit_view saves changes to the database. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think the changes to this file could be omitted. At least the cosmetic cleanups shouldn't be included. There are a number of docstrings that say, "A smoke test" which could be cleaned up together.
028c4f5
to
3318683
Compare
…save_as_new=True.
3318683
to
9bc4d90
Compare
https://code.djangoproject.com/ticket/14642