Opened 12 years ago
Closed 11 years ago
#10082 closed defect (worksforme)
TypeError: unexpected keyword argument 'field_type'
Reported by: | roskakori | Owned by: | osimons |
---|---|---|---|
Priority: | normal | Component: | CustomFieldAdminPlugin |
Severity: | normal | Keywords: | |
Cc: | Trac Release: | 0.12 |
Description
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/admin.py", line 109, in render_admin_panel File "build/bdist.macosx-10.6-x86_64/egg/customfieldadmin/api.py", line 161, in update_custom_field File "build/bdist.macosx-10.6-x86_64/egg/customfieldadmin/api.py", 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"), field_type=cfield['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:
[ticket-custom] some_date: date
Now it has to be:
[ticket-custom] some_date: text some_date.date = 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)s.date=true'"), {'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 'some_date.date=true'
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.