Changes between Version 7 and Version 8 of NewbieMistakes


Ignore:
Timestamp:
10/09/05 13:48:50 (9 years ago)
Author:
hugo
Comment:

hint about errors on single-char attribute errors

Legend:

Unmodified
Added
Removed
Modified
  • NewbieMistakes

    v7 v8  
    6161sessionlist.append(new_object)
    6262request.session['my_list'] = sessionlist
     63
     64== Errors about undefined attributes with one-char names ==
     65
     66==== Problem ====
     67
     68You get an AttributeError with some weird attribute name that's only one char long. You don't have that attribute name anywhere in your code.
     69
     70==== Solution ====
     71
     72Search your model and code for situations where you have to pass a tuple of values and want to pass a tuple with one element - and that element is a string like in this sample:
     73
     74{{{
     75#!python
     76class META:     
     77    ...
     78    admin = meta.Admin(
     79        list_display = ('total_price'),
     80        ...
     81    )
     82}}}
     83
     84It's a standard python error - you are just missing a comma in the list_display assignement like this:
     85
     86{{{
     87#!python
     88class META:     
     89    ...
     90    admin = meta.Admin(
     91        list_display = ('total_price',),
     92        ...
     93    )
     94}}}
     95
     96Since a tuple is expected but a string provided, the code will merrily iterate over the characters of the string instead of the tuple elements - and that's where the single-char attribute names come from.
Back to Top