[18.0] component: fix component init compat with py3.10#529
Closed
simahawk wants to merge 1 commit into
Closed
Conversation
Contributor
|
Hi @guewen, |
In Python 3.10, dynamically reassigning __bases__ on a class (as done in _build_component) incorrectly propagates slot descriptors from classes that become transitively reachable through the new MRO. odoo.models.BaseModel declares env as a __slots__ entry, which creates a data descriptor on the class. When _build_component rewrites ComponentClass.__bases__, Python 3.10 surfaces this slot descriptor in the component's MRO. Since the slot storage does not exist on component instances, any attempt to assign self.env = value raises AttributeError: can't set attribute. This bug was fixed in Python 3.12 (see cpython#95573), which is why the issue could not be reproduced locally. The fix defines env as a property with both getter and setter directly on AbstractComponent. Since AbstractComponent always precedes BaseModel in the built class MRO, the property descriptor takes priority, and self.env = value correctly routes through the setter regardless of Python version.
Contributor
Author
|
Does not work for 3.10. Rolling back here #530 |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
In Python 3.10, dynamically reassigning
__bases__on a class (as done in _build_component) incorrectly propagates slot descriptors from classes that become transitively reachable through the new MRO.odoo.models.BaseModeldeclares env as a__slots__entry, which creates a data descriptor on the class. When_build_componentrewritesComponentClass.__bases__, Python 3.10 surfaces this slot descriptor in the component's MRO. Since the slot storage does not exist on component instances, any attempt to assign self.env = value raisesAttributeError: can't set attribute.This bug was fixed in Python 3.12 (see cpython#95573), which is why the issue could not be reproduced locally.
The fix defines env as a property with both getter and setter directly on
AbstractComponent. SinceAbstractComponentalways precedesBaseModelin the built class MRO, the property descriptor takes priority, and self.env = value correctly routes through the setter regardless of Python version.Solves a problem introduced by #504
If this does not work we have to revert that PR.