~openerp-dev/openobject-server/saas-3-bug_1291322-ptr

« back to all changes in this revision

Viewing changes to openerp/osv/orm.py

  • Committer: Olivier Dony
  • Date: 2014-05-13 15:29:35 UTC
  • Revision ID: odo@openerp.com-20140513152935-tscga1ml7y1eb7cg
[FIX] orm.search_read: drop active_test context flag during the read() step

The active_test flag is meant for search(),
but when passed to search_read() it was also
propagated to the read() call.
This has little consequence normally because
read() ignores this flag, but it can have
side-effects when reading x2m fields or
function fields. They are likely to call
search() somewhere downstream, still with
 the propagated active_test flag, while
it should not be applied anymore.

Ultimately dropping this flag could be
done by read() in all cases, but changing
search_read() is less likely to block
exotic cases where the flag was passed
on purpose. Moving it to read() could
be done as a later step.

Show diffs side-by-side

added added

removed removed

Lines of Context:
5083
5083
            # shortcut read if we only want the ids
5084
5084
            return [{'id': id} for id in record_ids]
5085
5085
 
5086
 
        result = self.read(cr, uid, record_ids, fields, context=context)
 
5086
        # read() ignores active_test, but it would forward it to any downstream search call
 
5087
        # (e.g. for x2m or function fields), and this is not the desired behavior, the flag
 
5088
        # was presumably only meant for the main search().
 
5089
        # TODO: Move this to read() directly?                                                                                                
 
5090
        read_ctx = dict(context or {})                                                                                                       
 
5091
        read_ctx.pop('active_test', None)                                                                                                    
 
5092
                                                                                                                                             
 
5093
        result = self.read(cr, uid, record_ids, fields, context=read_ctx) 
5087
5094
        if len(result) <= 1:
5088
5095
            return result
5089
5096