__init__() got an unexpected keyword argument _ids

Hi! I’vw made a one2one field that relate user and party but when i try to save a party or a user with this new field filed i get this error:

Fault: RelacionPartyUser.__init__() got an unexpected keyword argument '_ids

Here’s my intermediate class model:

class RelacionPartyUser(ModelSQL):
    "RelacionPartyUser"
    __name__ = 'jardin.relacionpartyuser'
    
    origin = fields.Many2One('party.party','Origin')
    target = fields.Many2One('res.user','Target')

    def __init__(self):
        super(RelacionPartyUser, self).__init__()
        self._sql_constraints += [
            ('origin_unique','UNIQUE(origin)',
                'Origin must be unique'),
            ('target_unique','UNIQUE(target)',
                'Target must be unique')
        ]

My party.py:

from trytond.model import fields
from trytond.pool import PoolMeta

class Party(metaclass=PoolMeta):
    __name__ = 'party.party'
    usuario = fields.One2One(
        'jardin.relacionpartyuser','origin','target','Usuario')

My user.py:

from trytond.model import fields
from trytond.pool import PoolMeta

class User(metaclass=PoolMeta):
    __name__ = 'res.user'
    persona = fields.One2One(
        'jardin.relacionpartyuser','target','origin','Persona')

my relation table:

   Column    |              Type              | Collation | Nullable |                       Default                        
-------------+--------------------------------+-----------+----------+------------------------------------------------------
 id          | integer                        |           | not null | nextval('jardin_relacionpartyuser_id_seq'::regclass)
 create_date | timestamp(6) without time zone |           |          | 
 create_uid  | integer                        |           |          | 
 origin      | integer                        |           |          | 
 target      | integer                        |           |          | 
 write_date  | timestamp(6) without time zone |           |          | 
 write_uid   | integer                        |           |          | 
Indexes:
    "jardin_relacionpartyuser_pkey" PRIMARY KEY, btree (id)
    "idx_jardin_relacionpartyuser_148b804afcb562d610baf0e3d0089bf7" btree (target) WHERE target IS NOT NULL
    "idx_jardin_relacionpartyuser_fc2db724cf3f7f84bcc1828d1e3fa760" btree (origin) WHERE origin IS NOT NULL
Check constraints:
    "jardin_relacionpartyuser_id_positive" CHECK (id >= 0)
Foreign-key constraints:
    "jardin_relacionpartyuser_origin_fkey" FOREIGN KEY (origin) REFERENCES party_party(id) ON DELETE SET NULL
    "jardin_relacionpartyuser_target_fkey" FOREIGN KEY (target) REFERENCES res_user(id) ON DELETE SET NULL

I’m not sure this will fix your issue, but generally the _sql_constraints are not set in __init__ but in __setup__. Also I don’t think you are creating the constraints correctly - here is an example in the party module: modules/party/party.py · 7a9f94d3a7c8e8e02abd5c0545d367fb14f4e171 · Tryton / Tryton · GitLab

1 Like

Indeed as @dave said you shoud change your __init__ to a classmethod named __setup__.
The __init__ of the Models are seldomly overriden.

1 Like

This topic was automatically closed 30 days after the last reply. New replies are no longer allowed.