Odoo Help

Welcome!

This community is for beginners and experts willing to share their Odoo knowledge. It's not a forum to discuss ideas, but a knowledge base of questions and their answers.

0

TypeError: 'int' object has no attribute '__getitem__'

By
mike
on 4/12/13, 1:17 PM 11,193 views

....and why should it matter?

TypeError: 'int' object has no attribute '__getitem__'

In fields.py, line 1197, in fnct_read value = value[field] or False

def _fnct_read(self, obj, cr, uid, ids, field_name, args, context=None):
    res = {}
    for record in obj.browse(cr, SUPERUSER_ID, ids, context=context):
        value = record
        for field in self.arg:
            if isinstance(value, list):
                value = value[0]
            value = value[field] or False
            if not value:
                break
        res[record.id] = value

So it wants the record.id and seems to be getting an int value. It's throwing an error even though it gets what it wants! Why wasn't this passed in the expected type? And why isn't there a case for the expected value to be int in the 1st place?

This is for a custom addon model which simply defines some columns.

which line is 1197?

Mohammad Alhashash
on 4/12/13, 1:27 PM

line 1197, in fnct_read value = value[field] or False

mike
on 4/12/13, 1:29 PM
2

Mohammad Alhashash

--Mohammad Alhashash--
2075
| 5 5 8
Giza, Egypt
--Mohammad Alhashash--

Developer

Mohammad Alhashash
On 4/12/13, 1:57 PM

Apparently, you have a related field incorrectly defined. The first parameter of fields.related must be the relational field used to reach the target model.

If this is not the case, post your field definition.

That was the trick! I commented my relational fields and now no error. My related field is such - 'status':fields.related('id', 'state', type='char', relation='dbe.application', string='Application Status') and I copied it from the source of stock_inventory_line to get it right. Yet I still messed up! How?

mike
on 4/12/13, 2:19 PM

Found the problem. The referenced model also had a related field pointing back to this model and that one was set to type='many2one'. I changed it to char and no problem. Thanks!

mike
on 4/12/13, 4:28 PM

I don't get this error calling the form anymore but now I get it while saving. Hmmmm....

mike
on 4/16/13, 12:12 PM

Hello Mike, Have you found any solution regarding this issue? If yes please can you post the solution as i am facing same problem. Regards,

Pooja Zankhariya
on 3/26/14, 4:21 AM

Your Answer

Please try to give a substantial answer. If you wanted to comment on the question or answer, just use the commenting tool. Please remember that you can always revise your answers - no need to answer the same question twice. Also, please don't forget to vote - it really helps to select the best questions and answers!

About This Community

This community is for professionals and enthusiasts of our products and services. Read Guidelines

Question tools

0 follower(s)

Stats

Asked: 4/12/13, 1:17 PM
Seen: 11193 times
Last updated: 3/16/15, 8:10 AM