Conversation
|
Another way to prevent this recomputation is just created the SQL column on pre-migration script. This is done all across OpenUpgrade. |
|
@pedrobaeza I know and addressed this in the description of the PR. The precreation has the disadvantage that you have to do a lot of work to exactly match how the field would be created by the Odoo ORM. (including creating indexes where needed, etc.) With this PR we can just have the Odoo ORM do its work. It is in my opinion more reliable and a lot less work. |
|
OK, I didn't know about index creation (and I'm not sure about that part either). The problem with this is that you will need to forward-port and maintain this method for each OpenUpgrade version, and including in openupgradelib is not an option as you can imagine. |
There was a problem hiding this comment.
Why not _auto=False for avoiding table creation?
There was a problem hiding this comment.
I changed to _auto and a normal Model. Thanks for the suggestion!
|
How about adding the backlist as a property to models.BaseModel in openerp/models.py and check for that? |
|
In your pre script, you might be able to do: You should probably reset the property in the post script. |
|
@StefanRijnhart Just wondered how to set and use the property. When actually looking at the blacklist, the fields are recomputed for all models. Obviously I can determine the model, look it up in the registry, then look at the property, but would this not be more work/code then what I have now? |
|
Retrieve the model's blacklist from the recs variable. Proof of concept: At the point where you propose to intervene in method recompute(): |
|
BTW for the sake of clarity you could call it _openupgrade_recompute_fields_blacklist or something. |
762feca to
51a6006
Compare
|
@StefanRijnhart I rewrote the blacklist proposal according to your suggestions. Example of use in PR (that includes this PR): #663 |
| recs.browse(ids)._write(dict(vals)) | ||
| # mark computed fields as done | ||
| map(recs._recompute_done, fs) | ||
| # OpenUpgrade start, reset blacklists: |
There was a problem hiding this comment.
Looks like this resets the blacklist after every write. Is that what you want?
There was a problem hiding this comment.
@StefanRijnhart Actually not after every write, but after handling all the changes required by migrating one module. This takes care of your remark that the property will need to be reset in the post-migration, but without the need to do this manually. Otherwise the blacklist might still be active in other modules being migrated (or if the user actually logs into the migrated server to check the migration results).
There was a problem hiding this comment.
Am I missing something? On an Odoo 9.0 database with only 'base' ínstalled without demo data I have this patch:
--- a/openerp/models.py
+++ b/openerp/models.py
@@ -5863,6 +5863,7 @@ class BaseModel(object):
""" Recompute stored function fields. The fields and records to
recompute have been determined by method :meth:`modified`.
"""
+ print "Recompute called"
while self.env.has_todo():
field, recs = self.env.get_todo()
# determine the fields to recompute
if I do --update all, this is printed 1854 times.
There was a problem hiding this comment.
@StefanRijnhart Good catch. Other calls were due to database updates done during migration. Although code worked in practice, I moved the reset to a more appropriate place (I hope).
|
Thanks, looks like a useful addition! Upon merge this should be squashed for easy cherrypicking at least into 10.0. |
|
I found an issue that the blacklist is not always removed, because not all updated models are in the object list. |
|
Setting to work in progress as per your latest comment. |
[FIX] models: Fix blacklisting of fields when `recs` is false.
|
Hi @NL66278, Regarding what you have said about "an issue that the blacklist is not always removed, because not all updated models are in the object list." could you give me more details about the issue so that I can see if we can tackle it. |
|
Hi @mvaled When some models have blacklisted fields, but the migrated database does not require recomputation of a field in that model, the fields remain blacklisted, because they are not in the list used at this point: https://github.com/OCA/OpenUpgrade/pull/735/files#diff-a574457167ec463fe510488c27d95214L317 When in subsequent modules those fields do need recomputation, they are still in the list, and therefore not recomputed. |
|
So perhaps the approach would be to add/remove the blacklist at the migration boundaries. I'll be looking into it after a couple of hours I'm in the middle of a tough merge request from a colleague. |
|
Hi @NL66278, I'm a bit confused about your conclusion. I see that Reading the code of Am I right, or am I missing something? |
|
Hi @NL66278 Could you comment on my last remark in this PR? |
|
@mvaled You are missing something. I initially made the same assumptions as you. However when no recomputation takes place on a model, might be because there are no records needing recomputation, this model will not be in the obj_list. |
|
@NL66278 I think that happened before b9c5e6f. Before it, the removal of blacklisted fields was implemented in the I'm doing a little tracing with the following modification: diff --git a/openerp/modules/module.py b/openerp/modules/module.py
index a8676a5754b..278ff952488 100644
--- a/openerp/modules/module.py
+++ b/openerp/modules/module.py
@@ -308,6 +308,7 @@ def init_module_models(cr, module_name, obj_list):
"""
_logger.info('module %s: creating or updating database tables', module_name)
+ _logger.debug('module %s models: %r', module_name, obj_list)
todo = []
for obj in obj_list:
result = obj._auto_init(cr, {'module': module_name})
@@ -322,6 +323,7 @@ def init_module_models(cr, module_name, obj_list):
todo.sort(key=lambda x: x[0])
for t in todo:
t[1](cr, *t[2])
+ _logger.debug('module %s: finalizing and (possibly) reseting blacklists for %r', module_name, obj_list)
if obj_list:
# OpenUpgrade: Don't trigger workflows on recomputation
set_workflow_org = openerp.models.BaseModel.step_workflowWith that in place I see that modules where no recomputation is needed do log the I can also see that models modified are also finalized: |
|
What is the status of this? |
|
OK, I think so also. Then I close this. If not everything is already merged, then feel free to reopen. |
Description of the issue/feature this PR addresses: Recomputation of fields can take a long time, which is problematic when those fields will be filled with the correct values anyway.
Current behavior before PR: Only way to prevent long running unneeded computations was to create fields through SQL, which has the danger of not all attributes taken into account (like indexes) etc. Also takes a lot of code.
Desired behavior after PR is merged: It will be easy to supress feld recompute.
Example use: