Odoo xmlrpc, You are not allowed to modify on a read operation

1.2k views Asked by At

I'm trying to use the xmlrpc api of odoo 14. I have made a small script to do some tests. In the test I do a read operation but I get an xmlrpc.client.Fault exception, where odoo compains that I try to modify 'res.users' although my query is a read on 'res.partner'

Here is my test script. (Please note that the error is the same if I try to do a search_read instead of a search then read)

#! /usr/bin/env python3
import xmlrpc.client

url = <redacted>
base = <redacted>
user = <redacted>
key = <redacted>

try:
    api = xmlrpc.client.ServerProxy('{}/xmlrpc/2/common'.format(url))
    mod = xmlrpc.client.ServerProxy('{}/xmlrpc/2/object'.format(url))

    print("connection ... ", end='')
    uid = api.authenticate(base, user, key, {})
    print("ok. uid=",uid)

    print("listing partners  ... ", end='')
    partners = mod.execute_kw(base, uid, key, 'res.partner', 'search', [[]])
    print("ok. partners=", partners)

    print("fetching partner ... ", end='')
    res = mod.execute_kw(base, uid, key, 'res.partner', 'read', partners[:1])
    print("ok. partner=", res)
except xmlrpc.client.Fault as e:
    print("error !!!")
    print(str(e))

If I run this code I get :

connection ... ok. uid= 6
listing partners  ... ok. partners= [3, 15, 7, 10, 8, 9, 14, 13, 12, 11, 1, 16]
fetching partner ... error !!!
<Fault 4: "You are not allowed to modify 'Users' (res.users) records.\n\nThis operation is allowed for the following groups:\n\t- Administration/Access Rights\n\nContact your administrator to request access if necessary.">

I don't understand why it's trying to modify anything, since I'm doing a read.

Is it because of a computed field in a related model ? With that in mind, I also tried to choose the fields I wanted, and with this example the code works :

    print("fetching partner names ... ", end='')
    res = mod.execute_kw(base, uid, key, 'res.partner', 'read', partners[:1], {'fields': ['name']})
    print("ok. names=", res)

Edit:

Please note that this problem show up when logging with a user that has read access, but not write access.

1

There are 1 answers

9
Saumil gauswami On BEST ANSWER

Please check with this, what's giving in it.

models.execute_kw(base, uid, key, 'res.partner', 'check_access_rights', ['read'], {'raise_exception': False})

Solution:

When you read any record than all the compute and related fields refresh it's data so I think that will the cause the issue.