﻿id	summary	reporter	owner	description	type	status	component	version	severity	resolution	keywords	cc	stage	has_patch	needs_docs	needs_tests	needs_better_patch	easy	ui_ux
12341	unique_error_message() assumes field has label attribute, generates bad error message if not	Margie Roginski	nobody	"I have a model form and have overridden one of the fields in the form.  IE, I created a field that looks like this:

{{{
class CharField_CV(CharField):
    def __init__(self, *args, **kwargs):
        kwargs['show_hidden_initial'] = True
        super(CharField_CV, self).__init__(*args, **kwargs)
}}}

In my form I have code like this:

{{{
class ProjectForm(forms.ModelForm):
    class Meta:
        model = Project
        fields = (""name"", ""owner"", ""status"", ""description"")

    name = CharField_CV(max_length=Project._meta.get_field('name').max_length)
}}}

I find that because I did not use the label argument in my call to CharField_CV(), the label attribute of the field is not set.  In my Project model, name is declared like this:

    name=models.CharField(max_length=30, unique=True)

It seems that when BaseModelForm::unique_error_message() is called, it assumes that the field has a label attribute and the result is that the error message (in the case where the user specified a name that was not unique) is:

  Project with this None already exists

Other parts of the code take care of this by setting label based on the name of the field, if the label attribute doesn't exist.  For example, when a BoundField() is created from the field, it does this in __init__:

{{{
        if self.field.label is None:
            self.label = pretty_name(name)
        else:
            self.label = self.field.label
}}}


I realize this is a corner case bug and completely workaroundable (just specify the label argument when instantiating the field), but since I identified it, I just wanted to post it so that it is logged in case anyone else encounters it.

"		closed	Uncategorized	1.1		duplicate			Unreviewed	0	0	0	0	0	0
