Could we deprecate passing a single id to ORM methods

Bug #813974 reported by Numérigraphe
22
This bug affects 4 people
Affects Status Importance Assigned to Milestone
Odoo Server (MOVED TO GITHUB)
Confirmed
Wishlist
OpenERP's Framework R&D

Bug Description

Most ORM methods accept an "ids" argument which can be either an integer or a list of integers.
This is supported and well documented, and fixes have been accepted to support single integers (Bug #740202, Bug #812723 and probably others).

Unfortunately this is very badly known even among the core developers.
This regularly leads people to talk at cross purposes (as in Bug #740202) and it's also a bit controversial (as in https://lists.launchpad.net/openerp-expert-framework/msg00397.html).

As a consequence it may break in some new standard feature, and has never worked in numerous third-party modules.
Almost all the code in OpenERP passes "ids" as lists, even for only one element.
So, this feature is confusing and of little use.

Could it just be deprecated in the next version ?
A warning would be issued when an ORM method is called with a single int.
The documentation would be updated to indicate that "ids" should be a list, and a footnote would be added to explain that single integers are deprecated.

Then we could drop the feature completely in some later version.

Lionel Sausin.

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

I agree with this. We should make it clear. Support this feature, or don't support it. It's better than having an incoherent API, imo.

Revision history for this message
Vo Minh Thu (thu) wrote :

The present situation is indeed something we want to change.

But some details about what you propose, or given in the linked mailing list thread, are not right to me. The mail says that some methods are changed to accept a single id *instead* of a list of ids. The example commit doesn't say that. The real purpose of the commit is to bring a uniform API: accept *both* forms: either a single id, or a list of ids.

The fact is that the de facto API is to allow both. So this uniformity is brought back to some methods because there is no real reason to favor one or the other form for those methods.

It is clear for a large part of the community and core developers that allowing both form was a mistake. But having something uniform, without braking existing code was deemed more important than changing things. I don't think that we have an incoherent API, or that this flexibility is hardly used. But indeed it is an unfortunate flexibility and make the code harder to read and write than necessary.

One of the good reasons to think the situation is bad, is that in some situation, there is no reason to allow a list of ids, and thus the API seems inconsistent.

We do plan to change the situation. It is planned to bring a new API (in a broader sense, not just this id vs ids problem) and we will make sure to make clear when methods accept a single id or a list of ids, and that they don't accept both (i.e. most of the methods will only accept a list of ids, and when necessary, some will only accept a single id). The argument names will thus be in sync with the actual accepted argument types.

Revision history for this message
Thibaut DIRLIK (Logica) (thibaut-dirlik) wrote :

I suppose your are talking, for example, of on_change methods which take ids whereas you can't trigger an on_change on multiple ids ;-)

Do you plan to integrate the new API in 6.1 ? I saw good changes in that way (use of metaclass, etc). I hope you will continue this way.

Revision history for this message
Numérigraphe (numerigraphe) wrote :

More specifically, I was initially thinking of write() and unlink(): nobody seems to know they should accept ints.
But Vo Minh Thu is right, a broader reflexion is always a better move when changing an API.

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.