credativ team mailing list archive
-
credativ team
-
Mailing list archive
-
Message #00295
[Bug 890110] Re: new field default value is calculated only once during initialisation
Hello,
This is due to the way default value work, and it is the expected behavior, so I will close this bug.
The _default values are meant to be dynamic whenever a new record is going to be created manually. However this is not meant to be the case when a new column is added to an existing table. Normally all previous records should have NULLs for the new column, except when the column is actually NOT NULL (due to required=1).
In this case the ORM tries to workaround the problem by grabbing a default value for the new column and assigning it as default value. This does not support dynamic generation, and is not meant to. How would the ORM know if the value should be the same for all records or not? Should it do it one by one in all cases? What if there are billions of records?
In addition to the above, having a module add a required field on a
model from another module is kind of breaking the
modularity/encapsulation of OpenERP, and will make the data/demo records
in the original module invalid. This is not recommended, as it could for
example break the module's tests during an update (which will be run
without the other module being loaded, so without the new _defaults, and
could thus fail because it does not provide any value for the new
column).
If what you need is some sort of installation wizard to migrate existing
partners, I would suggest you provide it as a config wizard in your
module. Or possibly put a yaml script in your module's data to execute
the required procedure safely and in a controlled manner.
Not sure the above explanation is very clear, I hope you get the idea.
Thanks,
** Changed in: openobject-server
Status: Confirmed => Invalid
** Changed in: openobject-server
Assignee: OpenERP's Framework R&D (openerp-dev-framework) => (unassigned)
--
You received this bug notification because you are a member of OpenERP
Framework Experts, which is subscribed to OpenERP Server.
https://bugs.launchpad.net/bugs/890110
Title:
new field default value is calculated only once during initialisation
Status in OpenERP Server:
Invalid
Bug description:
OpenERP server 6.0.3
Steps to reproduce:
1) create new sequence
<record id="partner_code_sequence_code" model="ir.sequence.type">
<field name="name">Partner code sequence</field>
<field name="code">res.partner.code</field>
</record>
<record id="partner_code_sequence" model="ir.sequence">
<field name="name">Partner code sequence</field>
<field name="code">res.partner.code</field>
<field name="active">True</field>
<field name="prefix"></field>
<field name="padding">9</field>
<field name="number_increment">1</field>
<field name="number_next">1</field>
</record>
2) inherit res.partner, add new field with default value from sequence
class res_partner(osv.osv):
_inherit='res.partner'
_columns = {
'code': fields.char('Code', 9, required=True),
}
_defaults = {
'code': lambda self, cr, uid, *a: self.pool.get('ir.sequence').get(
cr, uid, 'res.partner.code'),
}
res_partner()
3) update database
Actual result: all existing partners have code "000000001"
Expected result: value of 'code' field calculated for each partner
To manage notifications about this bug go to:
https://bugs.launchpad.net/openobject-server/+bug/890110/+subscriptions