Context is not evaluted on one2many fields

Bug #865308 reported by Thibaut DIRLIK (Logica)
10
This bug affects 1 person
Affects Status Importance Assigned to Milestone
Odoo Web (MOVED TO GITHUB)
Fix Released
Low
OpenERP R&D Web Team

Bug Description

Hi,

I'm working on the trunk branch (updated this morning). When specifying a context on a one2many field in its "field" XML atg, it doesn't work. I join a module so you can test and reproduce the bug easily.

Example :

<!-- A many2one, it's ok -->
<field name="user_id" context="{'temporal_date' : date, 'dummy' : active_id}"/>
<!-- A one2many, it's does't work -->
<field name="fake_object_child_ids" context="{'this_does_not_work' : date, 'neither_this' : active_id}"/>

I got this error on GTK client :

Traceback (most recent call last):
  File "/home/thibaut/OpenERP 6/Logica/client/bin/tools/__init__.py", line 52, in expr_eval
    temp = eval(string, context)
  File "<string>", line 1, in <module>
NameError: name 'date' is not defined

And the same error with the active_id variable, whereras the first context work perfectly fine.

This is going to be a problem for the future base_temporal module : we won't be able to pass the temporal_date variable in the context based on a current form field. Moreover, not being able to use active_id in the context of a one2many field also is a problem to define default values in the one2many form view.

I hope this could be fixed before the 6.1 (7.0? ;-) !

Thanks for your time,

Revision history for this message
Thibaut DIRLIK (Logica) (thibaut-dirlik) wrote :
Changed in openobject-server:
assignee: nobody → OpenERP's Framework R&D (openerp-dev-framework)
importance: Undecided → Low
status: New → Confirmed
Revision history for this message
Naresh(OpenERP) (nch-openerp) wrote :

It should be fixed from client

affects: openobject-server → openobject-client
Changed in openobject-client:
assignee: OpenERP's Framework R&D (openerp-dev-framework) → OpenERP sa GTK client R&D (openerp-dev-gtk)
Revision history for this message
Thibaut DIRLIK (Logica) (thibaut-dirlik) wrote :

Their is the same problem on the openerp-web branch.

Revision history for this message
Naresh(OpenERP) (nch-openerp) wrote :

Hello Thibaut Dirlik,

Well this is not a bug ..let me elaborate a bit...

As you must be aware that context on O2M can have values like "form_view_ref","tree_view_ref","group_by","model fields from view" etc......Now as some context are required to be evaluated at the start i.e while creating the view at client such as form/tree_view_ref, group_by etc so that they can be used to perform their task. Now if we look at your scenario then you will have a traceback because of the context eval at view creation but if you see that the same context is being passed in the methods that needs it..like fields_view_get,read,create,default_get,etc..... In short I mean is that the traceback want cost you anything !

Can you please have a look at the context dict that you receive in the method that you intended !

Correct me if I am missing something !

regards,
Naresh

Changed in openobject-client:
status: Confirmed → Incomplete
Revision history for this message
Thibaut DIRLIK (Logica) (thibaut-dirlik) wrote : Re: [Bug 865308] Re: Context is not evaluted on one2many fields

Ok Naresh you are right, it is passed in the context of the methods
correctly.

Anyway, there still have a problem : The Web Client (6.1, openerp-web) stops
loading the view when it encounter these error.

2011/10/14 Naresh(OpenERP) <email address hidden>

> Hello Thibaut Dirlik,
>
> Well this is not a bug ..let me elaborate a bit...
>
> As you must be aware that context on O2M can have values like
> "form_view_ref","tree_view_ref","group_by","model fields from view"
> etc......Now as some context are required to be evaluated at the start
> i.e while creating the view at client such as form/tree_view_ref,
> group_by etc so that they can be used to perform their task. Now if we
> look at your scenario then you will have a traceback because of the
> context eval at view creation but if you see that the same context is
> being passed in the methods that needs it..like
> fields_view_get,read,create,default_get,etc..... In short I mean is that
> the traceback want cost you anything !
>
> Can you please have a look at the context dict that you receive in the
> method that you intended !
>
> Correct me if I am missing something !
>
> regards,
> Naresh
>
>
>
> ** Changed in: openobject-client
> Status: Confirmed => Incomplete
>
> --
> You received this bug notification because you are subscribed to the bug
> report.
> https://bugs.launchpad.net/bugs/865308
>
> Title:
> Context is not evaluted on one2many fields
>
> Status in OpenERP GTK Client:
> Incomplete
>
> Bug description:
> Hi,
>
> I'm working on the trunk branch (updated this morning). When
> specifying a context on a one2many field in its "field" XML atg, it
> doesn't work. I join a module so you can test and reproduce the bug
> easily.
>
> Example :
>
> <!-- A many2one, it's ok -->
> <field name="user_id" context="{'temporal_date' : date, 'dummy' :
> active_id}"/>
> <!-- A one2many, it's does't work -->
> <field name="fake_object_child_ids" context="{'this_does_not_work' : date,
> 'neither_this' : active_id}"/>
>
> I got this error on GTK client :
>
> Traceback (most recent call last):
> File "/home/thibaut/OpenERP 6/Logica/client/bin/tools/__init__.py", line
> 52, in expr_eval
> temp = eval(string, context)
> File "<string>", line 1, in <module>
> NameError: name 'date' is not defined
>
> And the same error with the active_id variable, whereras the first
> context work perfectly fine.
>
> This is going to be a problem for the future base_temporal module : we
> won't be able to pass the temporal_date variable in the context based
> on a current form field. Moreover, not being able to use active_id in
> the context of a one2many field also is a problem to define default
> values in the one2many form view.
>
> I hope this could be fixed before the 6.1 (7.0? ;-) !
>
> Thanks for your time,
>
> To manage notifications about this bug go to:
> https://bugs.launchpad.net/openobject-client/+bug/865308/+subscriptions
>

Revision history for this message
Naresh(OpenERP) (nch-openerp) wrote :

Ok, Thibault I would change the project let the web client track this...

affects: openobject-client → openobject-web
Changed in openobject-web:
assignee: OpenERP sa GTK client R&D (openerp-dev-gtk) → OpenERP R&D Web Team (openerp-dev-web)
status: Incomplete → New
affects: openobject-web → openerp-web
Changed in openerp-web:
status: New → Incomplete
Revision history for this message
Thibaut DIRLIK (Logica) (thibaut-dirlik) wrote :

Hi,

Why is it incomplete ? With the module I gave you you could be able to reproduce the web on the new webclient aren't you ?

Revision history for this message
Nicolas Vanhoren (OpenERP) (niv-openerp) wrote :

Hello Thibault.

Please note there are some problems in your bug report.

I see this:
<field name="fake_object_child_ids" context="{'this_does_not_work' : date, 'neither_this' : active_id}"/>

You don't tell me what 'date' represents. Is it a field? Something else?

Just telling me "Context is not evaluted on one2many fields" is not sufficient, and I know it's not true. I could cite you 10 examples in the OpenERP addons where that works. I don't say there is no bugs at all, that it works 100% of the time, but if I don't have enough information to reproduce this bug locally I can't resolve it, I can't even decide if it's a bug.

Plus you seem to conclude the active_id is not usable by simply relying on this same test, despite the fact that this test clearly fails due to that 'date' value that the context evaluator is not able to find.

Also please note that we know the web client stops when it encounters an error. That's a decision we made that the new web client would be less tolerant than the gtk client or the old web client, it was made on purpose and won't be changed. We prefer our program to completely crash with a big message when it encounters an error rather than trying to make stupid things to build an illusion of a working application.

Revision history for this message
Nicolas Vanhoren (OpenERP) (niv-openerp) wrote :

Oups, sorry, I didn't saw you posted a module :)

Changed in openerp-web:
status: Incomplete → New
Revision history for this message
Nicolas Vanhoren (OpenERP) (niv-openerp) wrote :

Ok, now I was able to investigate.

The problem with the 'date' field in the o2m was a bug I recently corrected, so it's not happening anymore.

About the active_id, it's normal it doesn't work in this case in the web client. active_id is supposed to be the id of the record in the preceding view. In the gtk client, there is always a preceding view. If you come from a menu, the preceding model is assumed to be ir.ui.menu and the active_id is the id of the menu.

The new web client doesn't do that because:
1 - It doesn't work the same way, the menu is not a view like any other else
2 - We never had any case in the OpenERP addons where it was useful to get the id of a menu.
3 - There was a lot of addons that were incorrectly coded and that assumed that active_id was the id of a record in the xxx model (replace xxx by any model except ir.ui.menu).

So we decided to not simulate that functionality in the new web client, since it's useless and tends to produce programming errors.

So, you can still use the active_id, but only when you come from a form/list/anything view, not from a menu. If you're not sure, you can test the active_id is defined by doing something like: {'neither_this' : context.get('active_id', False)} .

Changed in openerp-web:
status: New → Fix Released
Revision history for this message
Thibaut DIRLIK (Logica) (thibaut-dirlik) wrote :

Ok, I understand better. But, how do you do when you want, for example, to define a defalt value with "search_default_XXXX" with the id of the current objet you are on (guess it's a partner) ? If active_id is not available ?

Revision history for this message
Fossoul Thomas (fossoul-t) wrote :

omg..

To post a comment you must log in.
This report contains Public information  
Everyone can see this information.

Other bug subscribers

Remote bug watches

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