-
-
Notifications
You must be signed in to change notification settings - Fork 1.6k
[17.0][ADD] base_write_diff: new module
#3450
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: 17.0
Are you sure you want to change the base?
Conversation
legalsylvain
left a comment
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
interesting feature.
Could you share statistics on performance improvements, if you have any.
a54ca05 to
dc7c272
Compare
|
@legalsylvain hello 👋 To be honest, I don't have stats about performance diffs between the usage of However, the features included in this module were before included in a custom module we've been using in a production environment (for a few months now) within this context:
|
dc7c272 to
a3a64a7
Compare
yankinmax
left a comment
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks @SilvioC2C , great work!
base_write_diff/hooks.py
Outdated
|
|
||
|
|
||
| def post_load_hook(): | ||
| patch_base_model_write() |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
AFAIK post_load is executed globally (meant for server wide modules) and so in a multi-tenant deployment it would affect databases without this module installed.
AFAICS this is only needed for the context-based usage. TBH I'd drop it and keep only the explicit write_diff method usage (KISS)
Alternatively, if you want to keep it, I'd explore _register_hook / _unregister_hook. This is the mechanism used in the core base_automation module
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
That makes sense, thanks! I'll update the module accordingly.
a3a64a7 to
3eb249c
Compare
base_write_diff/models/base.py
Outdated
|
|
||
| from odoo.addons.web.models.models import RecordSnapshot | ||
|
|
||
| original_write = models.BaseModel.write |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This will not respect other modules doing the same thing, cause the original_write is evaluated at import time.
For example, this probably breaks the base_automation module hooks
You need to follow the pattern used in base_automation, that builds the patch method on the fly and uses write.origin(..) to call the original method
3eb249c to
b301baa
Compare
|
@ivantodorovich mind taking another look? It should be fine now |
|
IMO it's still wrong. In a multi-tenant deployment you'd have a race condition with several registries setting/unsetting We need to patch the registry's loaded model, not the BaseModel definition itself. For that the method needs to be created on-the-fly, and patched like this: https://github.com/odoo/odoo/blob/69828835c926485ec80ed92e14dd11fbc6c1caaa/addons/base_automation/models/base_automation.py#L786-L811 |
|
TBH I'm not even sure you need this, compared to a regular I thought you wanted the first scenario, cause that would make sense logically for me. ..but maybe I'm wrong, and you wanted the second one ? |
b301baa to
2a787d4
Compare
|
@ivantodorovich you're right, a |
|
This PR has the |
No description provided.