Opened 5 years ago

Closed 3 years ago

#10082 closed defect (worksforme)

TypeError: unexpected keyword argument 'field_type'

Reported by: roskakori Owned by: Odd Simon Simonsen
Priority: normal Component: CustomFieldAdminPlugin
Severity: normal Keywords:
Cc: Trac Release: 0.12


When upgrading our existing Trac installation and the related plugins we encountered the following error message when attempting to change the order of custom fields using Admin > Custom Fields and clicking "Apply Changes":

TypeError: __init__() got an unexpected keyword argument 'field_type'

The related stack trace is:

File "build/bdist.macosx-10.6-x86_64/egg/customfieldadmin/", line 109, in render_admin_panel
File "build/bdist.macosx-10.6-x86_64/egg/customfieldadmin/", line 161, in update_custom_field
File "build/bdist.macosx-10.6-x86_64/egg/customfieldadmin/", line 106, in verify_custom_field 

Version information: Mac OS X 10.6.8, Python 2.6, trac 0.12.2

The relevant parts of the source code in verify_custom_field read:

if not cfield['type'] in \
        ['text', 'checkbox', 'select', 'radio', 'textarea']:
    raise TracError(_("%(field_type)s is not a valid field type"),

Maybe field_type should be wrapped in a dictionary to raise the intended TracError:

    raise TracError(_("%(field_type)s is not a valid field type"),
            {'field_type': cfield['type']})

Even if the proper error message would have been raised the wording could be improved to make it clear what is expected:

_VALID_CFIELD_TYPES = ['text', 'checkbox', 'select', 'radio', 'textarea']
if not cfield['type'] in _VALID_CFIELD_TYPES:
    raise TracError(_("type of field %(field_name)s is '%(field_type)s' but must be one of: %(valid_types)s"),
            {'field_name': cfield['name'], 'field_type': cfield['type'], 'valid_types': _VALID_CFIELD_TYPES})

This should result in something like:

type of fileld some_date is 'date' but must be one of:
['text', 'checkbox', 'select', 'radio', 'textarea']

By the way the actual error was caused during our upgrade by the fact that DateFieldPlugin uses a different way to represent date fields now. Formerly it was:

some_date: date

Now it has to be:

some_date: text = true

As this might be a common case, an additional check for deprecated date fields might be helpful:

_VALID_CFIELD_TYPES = ['text', 'checkbox', 'select', 'radio', 'textarea']
if cfield['type'] == 'date':
    raise TracError(_("date field %(field_name)s must be migrated to new syntax in trac.ini, " + \
            "section [ticket-custom]: '%(field_name)s=text' and '%(field_name)'"),
            {'field_name': cfield['name']})

This would yield:

date field some_date must be migrated to new syntax in trac.ini, section [ticket-custom]:
'some_date=text' and ''

Attachments (0)

Change History (1)

comment:1 Changed 3 years ago by Odd Simon Simonsen

Resolution: worksforme
Status: newclosed

I've added a test for this in [13733]. Test passes, and I'm unable to recreate the original error now. There was likely some other code in your install affecting the use of the plugin.

Modify Ticket

Change Properties
Set your email in Preferences
as closed The owner will remain Odd Simon Simonsen.
The resolution will be deleted.

Add Comment

E-mail address and name can be saved in the Preferences.

Note: See TracTickets for help on using tickets.