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
[MERGE] core: introduce mechanism for selection_add
cleanup
#46325
Conversation
6312f3e
to
edb1d16
Compare
0418488
to
9994548
Compare
48b15b7
to
31c5e66
Compare
31c5e66
to
ed5d257
Compare
ed5d257
to
17481f1
Compare
73237d8
to
b45a2c5
Compare
38be7b6
to
72f36b8
Compare
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.
- maybe a
restrict
option (requiring the user to fix their records first) would make sense? - warning about the updates might be a good idea as well as some of the changes might be pretty brutal
ondelete = field.args.get('ondelete') or {} | ||
new_values = [kv[0] for kv in selection_add if kv[0] not in values] | ||
for key in new_values: | ||
ondelete.setdefault(key, 'set null') |
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.
Doesn't that mean there's always a value and the code in ir_model has no need to check for a missing / empty ondelete?
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.
Computed selection fields will have their ondelete set to None
(see above), if they don't define a selection_add
this will remain as None
and they will be treated the same as non-compute selection fields during _process_ondelete
'weight': 'set default', | ||
'location': 'set default', | ||
'lot': 'set default', | ||
'package': 'set default', |
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.
Did stock say to do that, rather than e.g. delete the rule? Because it seems a bit weird that we'd just convert stock barcode rules to "unit product"
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.
I invited them to review the code and they didn't seem to object to this particular change, but maybe you're right.
cc @sle-odoo
72f36b8
to
af59870
Compare
@xmo-odoo Don't think it makes sense to have an Thanks for the review |
Won't it? Couldn't we raise on a restrict if we find matching records? Though we can always add that option later if we have a use case for it anyway. |
This is necessary in order to create models on-the-fly within tests and to test improper Model / Field creation: registry.reset_changes will only perform the reset of the registry if it is invalidated, however if the setup of models crashes before it is invalidated (as is the case of a test), the reset_changes will not be triggered and thus the registry will be left dirty for subsequent tests.
- Let A and B be two different modules. - A defines a required Selection field F of model M and B extends it through the `selection_add` argument. - Create records of model M and have some of them have any of the options introduced by module B selected for field F. - Uninstall module B. The result will be records of Model M with an option for field F that no longer exists, this makes the registry inconsistent and prone to crashing (it is sufficient to access the form view of such a record to trigger a crash). This commit introduces a mechanism similar to the `ondelete` argument found in Many2one fields, the argument name is the same but it's different both in behaviour and in implementation. The `ondelete` mechanism for Selection fields is enforced for **any** Selection field with required set to `True`, this means that the developer is required to set a cleanup behaviour for when their module is uninstalled. For possible cleanup options, see fields.Selection's docstring. As far as implementation goes, everything is implemented in Python unlike with Many2one fields where the behaviour is delegated to PostgreSQL. The `ondelete` setting will be processed during `ir.model.fields.selection.unlink()` to ensure that the registry is left in an appropriate state after module uninstall.
With this commit, Selection fields with `required=True` which are extended via `selection_add` are given proper ondelete policies to ensure the cleanup of records containing these extended options during uninstall of the extending module. This commit also cleans up leftover uninstall hooks that were being used to handle the same set of problems prior to the ondelete mechanism being implemented for Selection fields.
af59870
to
1a311e3
Compare
@robodoo rebase-ff r+ |
Merge method set to rebase and fast-forward |
With this commit, Selection fields with `required=True` which are extended via `selection_add` are given proper ondelete policies to ensure the cleanup of records containing these extended options during uninstall of the extending module. This commit also cleans up leftover uninstall hooks that were being used to handle the same set of problems prior to the ondelete mechanism being implemented for Selection fields. closes #46325 Related: odoo/enterprise#9117 Signed-off-by: Raphael Collet (rco) <rco@openerp.com>
@Elkasitu good job! |
With this commit, Selection fields with `required=True` which are extended via `selection_add` are given proper ondelete policies to ensure the cleanup of records containing these extended options during uninstall of the extending module. This commit also cleans up leftover uninstall hooks that were being used to handle the same set of problems prior to the ondelete mechanism being implemented for Selection fields. closes odoo#46325 Related: odoo/enterprise#9117 Signed-off-by: Raphael Collet (rco) <rco@openerp.com>
Context and rationale
Selection
field F of model M and B extendsit through the
selection_add
argument.options introduced by module B selected for field F.
The result will be records of model M with an option for field F that no
longer exists, this makes the registry inconsistent and prone to
crashing (it is sufficient to access the form view of such a record to
trigger a crash).
This commit introduces a mechanism similar to the
ondelete
argumentfound in
Many2one
fields, the argument name is the same but it'sdifferent both in behaviour and in implementation.
The
ondelete
mechanism for Selection fields is enforced for anySelection
field withrequired
set toTrue
, this means that thedeveloper is required to set a cleanup behaviour for when their module
is uninstalled. For possible cleanup options, see the
fields.Selection
docstring.
As far as implementation goes, everything is implemented in Python
unlike with
Many2one
fields where the behaviour is delegated toPostgreSQL.
The
ondelete
setting will be processed duringir.model.fields.selection.unlink()
to ensure that the registry is leftin an appropriate state after module uninstall.
To do
Factorize_update_selections()
Handle custom field creationuninstall_hook
that handle this locallyNone
as'null'