On 03/31/2014 03:24 PM, Lionel Sausin wrote:
Le 31/03/2014 14:57, Lionel Sausin a écrit :
Dear Olivier,
In v7 I just noticed that check_recursion() is deprecated in favor of
_check_recursion().
That makes it a protected method, so by convention it should only be
used inside osv.orm shouldn't it?
Not really. Quoting PEP-8, the single underscore prefix in Python is only seen
as a "weak 'internal use' indicator". It separates public from non-public
members, but that doesn't mean non-public members are cannot be part of the
"subclass API" (aka protected).
PEP-8 explicitly suggests [1] the double leading underscore (name mangled)
convention for members that subclasses should not use.
In OpenERP the leading underscore convention similarly distinguishes public vs
non-public API methods: underscore-prefixed methods are not available in the
RPC API, and only meant for internal/subclass use.
[1] http://legacy.python.org/dev/peps/pep-0008/#designing-for-inheritance
Would you please be kind enough to explain the reason for this and if
it's OK to call _check_recursion() in our own "Model"s?
I'm asking because now pylint is looking down on me for using a
protected method - I just want to make I'm doing it right.
It's fine to call _check_recursion in your own Models. That method is
non-public because it is relatively low-level and could be a vector of SQL
injection. It's been deprecated for a while, even in 6.0 IIRC.
You can configure pylint globally to exclude that warning, or use pylint
comments to achieve the same.
Uh ok, I figured out I need to override _check_recursion in my own Model
anyway...
Sorry for the noise.
def _check_recursion(self, cr, uid, ids, context=None, parent=None):
return super(MyOwnModel, self)._check_recursion(
cr, uid, ids, context=context, parent=parent)
There is no need to override it unless you need to alter its behavior. The
following should work along with the relevant import:
_constraints = [
(osv.Model._check_recursion, 'Better error message', ['parent_id'])
]
_______________________________________________
Mailing list: https://launchpad.net/~openerp-community
Post to : [email protected]
Unsubscribe : https://launchpad.net/~openerp-community
More help : https://help.launchpad.net/ListHelp