← Back to team overview

openerp-india team mailing list archive

[Bug 1013566] [NEW] Inherit a Model from an AbstractModel has _auto=False

 

Public bug reported:

Hello,

It seems that there is a small issue when we use an AbstractModel.
By the way, I'm not sure if it is really destined to be used as I'm not able to find any usage in addons.
It's a pity because it allows to really modularize some things.

As instance, I tried to create a model with the "sequence"
responsibility :

class Sequencable(AbstractModel):

    _name = 'abstract.sequencable'

    _order = 'sequence'

    _columns = {
        'sequence': fields.integer('Sequence')
    }

    _defaults = {
        'sequence': 1000
    }

Then, in the models where I want a sequence, I just have to inherit from
'abstract.sequencable'.

class ModelA(Model):

    _name = 'model.a'
    _inherit = ['abstract.sequencable', 'other.inheritance']

    _columns = {...}

class ModelB(TransientModel):

    _name = 'model.b'
    _inherit = 'abstract.sequencable'

    _columns = {...}

First, do you see any reason not to do that ?


The once issue I've encountered is that _auto is set to False in TransientModel, and is not forced to True in Model and TransientModel

In orm.py with some cuts :
class AbstractModel(BaseModel):
    _auto = False # don't create any database backend for AbstractModels
    _register = False # not visible in ORM registry, meant to be python-inherited only

class Model(BaseModel):
    _register = False # not visible in ORM registry, meant to be python-inherited only
    _transient = False # True in a TransientModel

So as a result, I have to declare _auto = True in every materialized models; for my model.a it gives:
class ModelA(Model):

    _name = 'model.a'
    _inherit = ['abstract.sequencable', 'other.inheritance']
+    _auto = True

    _columns = {...}


As Model and TransiantModel are supposed to be concrete models, I think
that they have to be _auto = True by default even if they are
"_inherit"-ing an AbstractModel.

So the base model classes would be (without docstrings):
class Model(BaseModel):
    _register = False # not visible in ORM registry, meant to be python-inherited only
    _transient = False # True in a TransientModel
    _auto = True # create database backend for Models

class TransientModel(BaseModel):
    _register = False # not visible in ORM registry, meant to be python-inherited only
    _transient = True
    _auto = True # create database backend for TransientModels

class AbstractModel(BaseModel):
    _auto = False # don't create any database backend for AbstractModels
    _register = False # not visible in ORM registry, meant to be python-inherited only

Do you agree with that ?

Thanks
Guewen

** Affects: openobject-server
     Importance: Undecided
         Status: New

** Description changed:

  Hello,
  
  It seems that there is a small issue when we use an AbstractModel.
  By the way, I'm not sure if it is really destined to be used as I'm not able to find any usage in addons.
  It's a pity because it allows to really modularize some things.
  
- 
- As instance, I tried to create a model with the "sequence" responsibility : 
+ As instance, I tried to create a model with the "sequence"
+ responsibility :
  
  class Sequencable(AbstractModel):
  
-     _name = 'abstract.sequencable'
+     _name = 'abstract.sequencable'
  
-     _order = 'sequence'
+     _order = 'sequence'
  
-     _columns = {
-         'sequence': fields.integer('Sequence')
-     }
+     _columns = {
+         'sequence': fields.integer('Sequence')
+     }
  
-     _defaults = {
-         'sequence': 1000
-     }
+     _defaults = {
+         'sequence': 1000
+     }
  
  Then, in the models where I want a sequence, I just have to inherit from
  'abstract.sequencable'.
  
  class ModelA(Model):
  
-     _name = 'model.a'
-     _inherit = ['abstract.sequencable', 'other.inheritance']
+     _name = 'model.a'
+     _inherit = ['abstract.sequencable', 'other.inheritance']
  
-     _columns = {...}
- 
+     _columns = {...}
  
  class ModelB(TransientModel):
  
-     _name = 'model.b'
-     _inherit = 'abstract.sequencable'
+     _name = 'model.b'
+     _inherit = 'abstract.sequencable'
  
-     _columns = {...}
+     _columns = {...}
  
- 
- First, do you see any reason not to do that ? 
+ First, do you see any reason not to do that ?
  
  
  The once issue I've encountered is that _auto is set to False in TransientModel, and is not forced to True in Model and TransientModel
  
  In orm.py with some cuts :
  class AbstractModel(BaseModel):
-     _auto = False # don't create any database backend for AbstractModels
-     _register = False # not visible in ORM registry, meant to be python-inherited only
+     _auto = False # don't create any database backend for AbstractModels
+     _register = False # not visible in ORM registry, meant to be python-inherited only
  
  class Model(BaseModel):
-     _register = False # not visible in ORM registry, meant to be python-inherited only
-     _transient = False # True in a TransientModel
+     _register = False # not visible in ORM registry, meant to be python-inherited only
+     _transient = False # True in a TransientModel
+ 
+ So as a result, I have to declare _auto = True in every materialized models; for my model.a it gives:
+ class ModelA(Model):
+ 
+     _name = 'model.a'
+     _inherit = ['abstract.sequencable', 'other.inheritance']
+ +    _auto = True
+ 
+     _columns = {...}
  
  
- So as a result, I have to declare _auto = True in every materialized models. So with my model.a I had to to:
- class ModelA(Model):
- 
-     _name = 'model.a'
-     _inherit = ['abstract.sequencable', 'other.inheritance']
-    _auto = True
- 
-     _columns = {...}
- 
- 
- As Model and TransiantModel are supposed to be concrete models, I think that they have to be _auto = True by default even if they are "_inherit"-ing an AbstractModel.
+ As Model and TransiantModel are supposed to be concrete models, I think
+ that they have to be _auto = True by default even if they are
+ "_inherit"-ing an AbstractModel.
  
  So the base model classes would be (without docstrings):
  class Model(BaseModel):
-     _register = False # not visible in ORM registry, meant to be python-inherited only
-     _transient = False # True in a TransientModel
-     _auto = True # create database backend for Models
+     _register = False # not visible in ORM registry, meant to be python-inherited only
+     _transient = False # True in a TransientModel
+     _auto = True # create database backend for Models
  
  class TransientModel(BaseModel):
-     _register = False # not visible in ORM registry, meant to be python-inherited only
-     _transient = True
-     _auto = True # create database backend for TransientModels
+     _register = False # not visible in ORM registry, meant to be python-inherited only
+     _transient = True
+     _auto = True # create database backend for TransientModels
  
  class AbstractModel(BaseModel):
-     _auto = False # don't create any database backend for AbstractModels
-     _register = False # not visible in ORM registry, meant to be python-inherited only
- 
+     _auto = False # don't create any database backend for AbstractModels
+     _register = False # not visible in ORM registry, meant to be python-inherited only
  
  Do you agree with that ?
  
  Thanks
  Guewen

-- 
You received this bug notification because you are a member of OpenERP
Indian Team, which is subscribed to OpenERP Server.
https://bugs.launchpad.net/bugs/1013566

Title:
  Inherit a Model from an AbstractModel has _auto=False

Status in OpenERP Server:
  New

Bug description:
  Hello,

  It seems that there is a small issue when we use an AbstractModel.
  By the way, I'm not sure if it is really destined to be used as I'm not able to find any usage in addons.
  It's a pity because it allows to really modularize some things.

  As instance, I tried to create a model with the "sequence"
  responsibility :

  class Sequencable(AbstractModel):

      _name = 'abstract.sequencable'

      _order = 'sequence'

      _columns = {
          'sequence': fields.integer('Sequence')
      }

      _defaults = {
          'sequence': 1000
      }

  Then, in the models where I want a sequence, I just have to inherit
  from 'abstract.sequencable'.

  class ModelA(Model):

      _name = 'model.a'
      _inherit = ['abstract.sequencable', 'other.inheritance']

      _columns = {...}

  class ModelB(TransientModel):

      _name = 'model.b'
      _inherit = 'abstract.sequencable'

      _columns = {...}

  First, do you see any reason not to do that ?

  
  The once issue I've encountered is that _auto is set to False in TransientModel, and is not forced to True in Model and TransientModel

  In orm.py with some cuts :
  class AbstractModel(BaseModel):
      _auto = False # don't create any database backend for AbstractModels
      _register = False # not visible in ORM registry, meant to be python-inherited only

  class Model(BaseModel):
      _register = False # not visible in ORM registry, meant to be python-inherited only
      _transient = False # True in a TransientModel

  So as a result, I have to declare _auto = True in every materialized models; for my model.a it gives:
  class ModelA(Model):

      _name = 'model.a'
      _inherit = ['abstract.sequencable', 'other.inheritance']
  +    _auto = True

      _columns = {...}


  As Model and TransiantModel are supposed to be concrete models, I
  think that they have to be _auto = True by default even if they are
  "_inherit"-ing an AbstractModel.

  So the base model classes would be (without docstrings):
  class Model(BaseModel):
      _register = False # not visible in ORM registry, meant to be python-inherited only
      _transient = False # True in a TransientModel
      _auto = True # create database backend for Models

  class TransientModel(BaseModel):
      _register = False # not visible in ORM registry, meant to be python-inherited only
      _transient = True
      _auto = True # create database backend for TransientModels

  class AbstractModel(BaseModel):
      _auto = False # don't create any database backend for AbstractModels
      _register = False # not visible in ORM registry, meant to be python-inherited only

  Do you agree with that ?

  Thanks
  Guewen

To manage notifications about this bug go to:
https://bugs.launchpad.net/openobject-server/+bug/1013566/+subscriptions


Follow ups

References