Opened 9 years ago

Closed 9 years ago

Last modified 9 years ago

#3140 closed defect (duplicate)

"float argument required" exception in admin_list

Reported by: nick@… Owned by: adrian
Component: contrib.admin Version: master
Severity: normal Keywords:
Cc: Triage Stage: Unreviewed
Has patch: no Needs documentation: no
Needs tests: no Patch needs improvement: no
Easy pickings: UI/UX:

Description

I get the following exception in the admin app when trying to view a list of objects with a float field in the list_display options:

Exception Type: TypeError
Exception Value: float argument required
Exception Location: /usr/lib/python2.4/site-packages/django/contrib/admin/templatetags/admin_list.py in items_for_result, line 155

However, I don't get this error on my development server which is running SQLite (my "production" server is running MySQL).

The code in question:

152 	            # FloatFields are special: Zero-pad the decimals.
153 	            elif isinstance(f, models.FloatField):
154 	                if field_val is not None:
155 	                    result_repr = ('%%.%sf' % f.decimal_places) % field_val
156 	                else:
157 	                    result_repr = EMPTY_CHANGELIST_VALUE

If I add a float() around the field_val it fixes the problem, e.g.:

152 	            # FloatFields are special: Zero-pad the decimals.
153 	            elif isinstance(f, models.FloatField):
154 	                if field_val is not None:
155 	                    result_repr = ('%%.%sf' % f.decimal_places) % float(field_val)
156 	                else:
157 	                    result_repr = EMPTY_CHANGELIST_VALUE

It looks like the MySQL backend is returning a string for the field_val or something?

Change History (2)

comment:1 Changed 9 years ago by anonymous

  • Resolution set to duplicate
  • Status changed from new to closed

comment:2 Changed 9 years ago by anonymous

Duplicate of #2917

Note: See TracTickets for help on using tickets.
Back to Top