Skip to Content
Menu
This question has been flagged
1 Reply
2069 Views

I am always getting ValueError: Expected singleton: this error Can I get to undestand what the main solution to it pleaase

Avatar
Discard
Best Answer

Hi Loomoni Morwo ,

Recordset with only one record is called a singleton , 

>>> partner =  self.env['res.partner'].search([('name', 'like', 'Odoo')])
>>> print(partner)
res.partner(72,) // recordset with single record
>>> print(partner.name)
Odoo

Error is because recordset contain multiple records,

>>> partner =  self.env['res.partner'].search([('name', 'like', 'Odoo')])
>>> print(partner)
res.partner(72,75) // recordset with multiple record
>>> print(partner.name) // Printing recordset with multiple records , it throws singleton error 
Expected singleton: res.partner(72,75)

To avoid these kind of error make sure you loop through recordset.

>>> partner =  self.env['res.partner'].search([('name', 'like', 'Odoo')])
>>> print(partner)
res.partner(72,75)
>>> for rec in partner :
>>>      print(rec.name)
Odoo
Odoo1

Hope it helps ,

Kiran

Avatar
Discard