6.1RC1: 'uid' not available in attrs evaluation context

Bug #920033 reported by Hardik Shah
48
This bug affects 7 people
Affects Status Importance Assigned to Milestone
Odoo Server (MOVED TO GITHUB)
Opinion
Medium
OpenERP's Framework R&D

Bug Description

When I try to compare the logged in user with the user_id stored on the database to run time display a field or button using attrs="{'invisible':[('user_id','=',uid)]}", it does not work.

Was working in previous versions. Please suggest a fix.

Related branches

Revision history for this message
Olivier Dony (Odoo) (odo-openerp) wrote :

Hi,

The "uid" dynamic value is not a valid field to be evaluated client-side. This was working previously because the clients (GTK/Web) happened to have a "uid" value available in the evaluation context, but that is not guaranteed to be the case, as far as I know.
What you are trying to do seems a little bit of a corner case (none of the standard addons do it), so I'm not sure it would be worth adding a global "uid" value to client-side evaluation context.

What we often want to do is to selectively hide fields based on user groups or document states. These 2 cases are covered by the API with the ``states`` and ``groups`` attributes.
Here you want the behavior to differ when the user is viewing one of her "own documents". A simple workaround to accomplish this would be to add a function field to that document, and have it always return the current user ID. If you named the field "uid" you could probably keep your existing `attrs`.

As for adding "uid" to the default client-side (web) evaluation context, and making it a permanent API feature, it should be discussed with the web team, so I'm reassigning it to them.

summary: - [6.1[RC]]: Cannot use uid along with attrs
+ 6.1RC1: 'uid' not available in attrs evaluation context
affects: openobject-server → openerp-web
Changed in openerp-web:
status: New → Triaged
assignee: nobody → OpenERP R&D Web Team (openerp-dev-web)
milestone: none → 6.1
Revision history for this message
Xavier (Open ERP) (xmo-deactivatedaccount) wrote :

Added a uid in the context sent through fields_view_get (as attrs are partially processed server-side for the web client). Should work now.

Changed in openerp-web:
status: Triaged → Fix Released
affects: openerp-web → openobject-server
Changed in openobject-server:
milestone: 6.1 → none
assignee: OpenERP R&D Web Team (openerp-dev-web) → OpenERP's Framework R&D (openerp-dev-framework)
importance: Undecided → Medium
status: Fix Released → Confirmed
Revision history for this message
Jignesh Rathod(OpenERP) (jir-openerp) wrote :
Download full text (3.2 KiB)

Hello ,

I am still face the same problem with web as well as gtk.
when use attrs="{'invisible':[('user_id','=',uid)]}"

I have face following traceback

Environment Information :
System : Linux-2.6.32-21-generic-i686-with-Ubuntu-10.04-lucid
OS Name : posix
Distributor ID: Ubuntu
Description: Ubuntu 10.04.3 LTS
Release: 10.04
Codename: lucid
Operating System Release : 2.6.32-21-generic
Operating System Version : #32-Ubuntu SMP Fri Apr 16 08:10:02 UTC 2010
Operating System Architecture : 32bit
Operating System Locale : en_IN.ISO8859-1
Python Version : 2.6.5
OpenERP-Client Version : 6.1
Last revision No. & ID :2050 launchpad_translations_on_behalf_of_openerp-20120219054202-yts5mlg7pe20l36a
Traceback (most recent call last):
  File "/home/jir/workspace/trunk6/server/openerp/wsgi/core.py", line 79, in xmlrpc_return
    result = openerp.netsvc.dispatch_rpc(service, method, params)
  File "/home/jir/workspace/trunk6/server/openerp/netsvc.py", line 360, in dispatch_rpc
    result = ExportService.getService(service_name).dispatch(method, params)
  File "/home/jir/workspace/trunk6/server/openerp/service/web_services.py", line 572, in dispatch
    res = fn(db, uid, *params)
  File "/home/jir/workspace/trunk6/server/openerp/osv/osv.py", line 121, in wrapper
    return f(self, dbname, *args, **kwargs)
  File "/home/jir/workspace/trunk6/server/openerp/osv/osv.py", line 176, in execute
    res = self.execute_cr(cr, uid, obj, method, *args, **kw)
  File "/home/jir/workspace/trunk6/server/openerp/osv/osv.py", line 164, in execute_cr
    return getattr(object, method)(cr, uid, *args, **kw)
  File "/home/jir/workspace/trunk6/server/openerp/osv/orm.py", line 2149, in fields_view_get
    xarch, xfields = self.__view_look_dom_arch(cr, user, result['arch'], view_id, context=ctx)
  File "/home/jir/workspace/trunk6/server/openerp/osv/orm.py", line 1789, in __view_look_dom_arch
    fields_def = self.__view_look_dom(cr, user, node, view_id, False, fields, context=context)
  File "/home/jir/workspace/trunk6/server/openerp/osv/orm.py", line 1738, in __view_look_dom
    fields.update(self.__view_look_dom(cr, user, f, view_id, in_tree_view, model_fields, context))
  File "/home/jir/workspace/trunk6/server/openerp/osv/orm.py", line 1738, in __view_look_dom
    fields.update(self.__view_look_dom(cr, user, f, view_id, in_tree_view, model_fields, context))
  File "/home/jir/workspace/trunk6/server/openerp/osv/orm.py", line 1738, in __view_look_dom
    fields.update(self.__view_look_dom(cr, user, f, view_id, in_tree_view, model_fields, context))
  File "/home/jir/workspace/trunk6/server/openerp/osv/orm.py", line 1738, in __view_look_dom
    fields.update(self.__view_look_dom(cr, user, f, view_id, in_tree_view, model_fields, context))
  File "/home/jir/workspace/trunk6/server/openerp/osv/orm.py", line 1709, in __view_look_dom
    transfer_node_to_modifiers(node, modifiers, context, in_tree_view)
  File "/home/jir/workspace/trunk6/server/openerp/osv/orm.py", line 99, in transfer_node_to_modifiers
    modifiers.update(eval(node.get('attrs')))
  File "/home/jir/workspace/trunk6/server/openerp/tools/safe_eval.py", line 241, in safe_eval
    return eval(test_expr(expr,_SAFE_OPCODE...

Read more...

Revision history for this message
Serpent Consulting Services (serpent-consulting-services) wrote :

Does this patch do a trick?

We are working on it, we may come across a better solution

Regards,
Serpent Consulting Services.

Jigar A. (ifixthat)
Changed in openobject-server:
status: Confirmed → In Progress
Revision history for this message
Jigar A. (ifixthat) wrote :

Hello Hardik,
     Thanks for pointing issue, we have tested the issue and Have fixed the issue. Fix is Combined in 2 branched per project, gtk and server and WebClient (as Per comment#2 WebFix is Already Done) and rest of the fix as follow:
     GTK Client Fix : lp:~openerp-dev/openobject-client/trunk-bug-920033-jam
     Server FIX : lp:~openerp-dev/openobject-server/trunk-bug-920033-jam
     We have already proposed fix for merging in respective branches of the project. It will be soon reviewed and merged
Thanks for your Kind Support.

Hello Serpent Consulting Services,
We can not accept your whole solution instead solution suggest by Olivier Dony in Comment#1 is feasible and concrete.
We Appreciate your contribution, Thanks for your time and Consideration.

Changed in openobject-server:
status: In Progress → Fix Committed
Revision history for this message
Jaf Faizal (jaffaizal) wrote :

Hi Jigar,

I am a newbie. This problem exist in my OpenERP v 6.1.1

How to solve it?

Thank you

Changed in openobject-server:
status: Fix Committed → Invalid
peer chan (baggio)
Changed in openobject-server:
status: Invalid → Fix Released
Changed in openobject-server:
status: Fix Released → Invalid
snowkite (snowkite)
Changed in openobject-server:
status: Invalid → Opinion
To post a comment you must log in.
This report contains Public information  
Everyone can see this information.

Duplicates of this bug

Other bug subscribers

Remote bug watches

Bug watches keep track of this bug in other bug trackers.