From a3e9e9e6c6dc9ccff85c2a6d8db88cc207127f0c Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Petras=20Zdanavi=C4=8Dius?= Date: Mon, 8 Sep 2014 22:54:57 +0300 Subject: [PATCH] [1.7.x] Fixed #23451 -- Fixed typo in inlineformset_factory() error message. Backport of f7eee04ebe from master --- django/forms/models.py | 2 +- docs/releases/1.7.1.txt | 3 +++ tests/model_formsets/tests.py | 6 ++++++ 3 files changed, 10 insertions(+), 1 deletion(-) diff --git a/django/forms/models.py b/django/forms/models.py index 76f5bb8197..0f21a43655 100644 --- a/django/forms/models.py +++ b/django/forms/models.py @@ -950,7 +950,7 @@ def _get_foreign_key(parent_model, model, fk_name=None, can_fail=False): (fk.rel.to != parent_model and fk.rel.to not in parent_model._meta.get_parent_list()): raise ValueError( - "fk_name '%s' is not a ForeignKey to '%s.%'." + "fk_name '%s' is not a ForeignKey to '%s.%s'." % (fk_name, parent_model._meta.app_label, parent_model._meta.object_name)) elif len(fks_to_parent) == 0: raise ValueError( diff --git a/docs/releases/1.7.1.txt b/docs/releases/1.7.1.txt index 85421f2fa4..368749f595 100644 --- a/docs/releases/1.7.1.txt +++ b/docs/releases/1.7.1.txt @@ -23,3 +23,6 @@ Bugfixes * The ``@deconstructible`` decorator now fails with a ``ValueError`` if the decorated object cannot automatically be imported (:ticket:`23418`). + +* Fixed a typo in an ``inlineformset_factory()`` error message that caused a + crash (:ticket:`23451`). diff --git a/tests/model_formsets/tests.py b/tests/model_formsets/tests.py index 07f5ccf18b..e814a2950b 100644 --- a/tests/model_formsets/tests.py +++ b/tests/model_formsets/tests.py @@ -805,6 +805,12 @@ class ModelFormsetTest(TestCase): formset = AuthorBooksFormSet(data, instance=author, queryset=custom_qs) self.assertTrue(formset.is_valid()) + def test_inline_formsets_with_wrong_fk_name(self): + """ Regression for #23451 """ + message = "fk_name 'title' is not a ForeignKey to 'model_formsets.Author'." + with self.assertRaisesMessage(ValueError, message): + inlineformset_factory(Author, Book, fields="__all__", fk_name='title') + def test_custom_pk(self): # We need to ensure that it is displayed