passing int to write method of stock.move gives "Field '0' does not exist in object 'browse_record(stock.move,..."

Bug #740202 reported by Lorenzo Battistini
12
This bug affects 1 person
Affects Status Importance Assigned to Milestone
Odoo Addons (MOVED TO GITHUB)
Fix Released
Low
OpenERP R&D Addons Team 2

Bug Description

- Call the write method of stock.move passing ids as INT (instead of LIST) with user != admin
- Get
  File "server/bin/addons/stock/stock.py", line 1616, in write
    for move in self.browse(cr, uid, ids, context=context):
  File "server/bin/osv/orm.py", line 189, in __getitem__
    name, self))
KeyError: "Field '0' does not exist in object 'browse_record(stock.move, 422)'"

Suggested FIX:
After line 1614 ( http://bazaar.launchpad.net/~openerp/openobject-addons/trunk/view/4567/stock/stock.py#L1611 ) add

            if isinstance(ids, (int, long)):
                ids = [ids]

Related branches

Revision history for this message
Amit Parik (amit-parik) wrote :

Hello,

This situation will never happen in system until and unless we will create it manually.
So we will not consider it as a bug.

Thanks.

Changed in openobject-addons:
status: New → Invalid
Revision history for this message
Lorenzo Battistini (elbati) wrote :

So, the statement at http://doc.openerp.com/v6.0/developer/2_5_Objects_Fields_Methods/methods.html#osv.osv.osv.write "Param ids: object id or list of object ids to update" has to be considered wrong?

So, any other module can't write a stock.move passing its id?

See for instance mrp_prodlot_autosplit: http://bazaar.launchpad.net/~openerp-commiter/openobject-addons/extra-6.0/view/5310/mrp_prodlot_autosplit/stock.py#L109 that is behaving right according to ORM specifications

Changed in openobject-addons:
status: Invalid → New
Revision history for this message
Amit Parik (amit-parik) wrote :

Hello Lorenzo,

I have tested your scenario but this situation is never happen at my end So I am not able to reproduce this bug.
would you please provide the proper steps to reproduce it.

Thanks.

Changed in openobject-addons:
status: New → Incomplete
Revision history for this message
Lorenzo Battistini (elbati) wrote :

Hello Amit,

1- Install purchase
2- Install mrp_prodlot_autosplit
3- Add new user (with every privilege)
4- Log in as new user
5- Create new stockable product selecting 'Track incoming lots', 'Track outgoing lots' and 'Unique production number'
6- Try to purchase 3 units of the created product
7- Get "Field '0' does not exist in object 'browse_record(stock.move, 1)'"

Changed in openobject-addons:
status: Incomplete → New
Revision history for this message
Vinay Rana (OpenERP) (vra-openerp) wrote :

Hello ,

This has been fixed with the 5311 <email address hidden> revision of extra-trunk.

Thanks.

Changed in openobject-addons:
status: New → Fix Released
Revision history for this message
Lorenzo Battistini (elbati) wrote :

Hello Vinay Rana,

this is not a bug of mrp_prodlot_autosplit, otherwise I could fix it by myself.

If you read http://doc.openerp.com/v6.0/developer/2_5_Objects_Fields_Methods/methods.html#osv.osv.osv.write , you'll see that must be possible to write a record by passing its ID (besides ID list).

If your answer is "mrp_prodlot_autosplit has to pass a list of ids", this makes the developer book erroneous and forces every other modules calling that method to use always LIST, instead of allowing the choice to use INT or LIST.

Please fix the write method of 'stock.move' as described above.

Changed in openobject-addons:
status: Fix Released → New
Revision history for this message
Davide Corio (enlightx-deactivatedaccount) wrote :

I completely agree with Lorenzo, the ORM must respect what the manual says (or vice-versat)

Revision history for this message
Vinay Rana (OpenERP) (vra-openerp) wrote :

Hello Lorenzo and Davide,

What I want say is always pass list, Our argument explain its self that this is not a single value. 'ids' always fill with list not any other value.
There are so many places where we are defining write method and It is not necessary that we need to include the list and single value fixes condition.

I am not consider this as a bug, This is programmer mistake so It should be improve in calling side code not in main code.

Thanks.

Changed in openobject-addons:
status: New → Invalid
Revision history for this message
Lorenzo Battistini (elbati) wrote :

So, the statement at http://doc.openerp.com/v6.0/developer/2_5_Objects_Fields_Methods/methods.html#osv.osv.osv.write
"Param ids: object ID or list of object ids to update"
has to be considered wrong? (again... https://bugs.launchpad.net/openobject-addons/+bug/740202/comments/2 )

What about "Param ids: object ID"? Are you declaring that I can't pass 'object ID'?

Changed in openobject-addons:
status: Invalid → New
Revision history for this message
Leonardo Pistone (lepistone) wrote :

Hello Vinay,

what you say is ok. The only thing Lorenzo and Davide are trying to say is that if we do like you suggest, then the manual is wrong and should be changed where it says "Param ids: object id or list of object ids". As simple as that: at the moment the manual and the write() code say two different things, therefore one of the two must be changed.

Regards

Revision history for this message
Vinay Rana (OpenERP) (vra-openerp) wrote :

Hello Leonardo,

I am confirming this issue.Here the only problem is due to 'ids' variable, Which is directly passing in the loop (with out checking).so If ids is assign with single value then it should first assign with list and then will pass into loop.

Thanks for pointing this.

Thanks for reporting this issue.

Changed in openobject-addons:
assignee: nobody → OpenERP R&D Addons Team 2 (openerp-dev-addons2)
importance: Undecided → Low
status: New → Confirmed
Changed in openobject-addons:
status: Confirmed → In Progress
Revision history for this message
Rohan Nayani(Open ERP) (ron-tinyerp) wrote :

Hello,

Thanks for Reporting.
It has been fixed in lp:~openerp-dev/openobject-addons/trunk-bug-740202-ron
Revision ID: <email address hidden>
Revision num:4607.

It will be available in trunk soon,

Changed in openobject-addons:
status: In Progress → Fix Committed
qdp (OpenERP) (qdp)
Changed in openobject-addons:
status: Fix Committed → Fix Released
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.