[14.0][ADD] pydantic: allows pydantic use into Odoo#218
[14.0][ADD] pydantic: allows pydantic use into Odoo#218
Conversation
0d0011e to
19499a4
Compare
19499a4 to
a9e2ebe
Compare
c060822 to
245d6bb
Compare
245d6bb to
4090cf9
Compare
| field = self._obj._fields[key] | ||
| if field.type in ["one2many", "many2many"]: | ||
| return list(res) | ||
| return res |
There was a problem hiding this comment.
Is there anything needed to convert False to None here ?
adcd8c1 to
1418e06
Compare
Co-authored-by: Yannick Vaucher <yannick.vaucher@camptocamp.com>
|
Hello @lmignon I'm testing pydantic on 15.0 using python 3.9. I get an error when I try to define a model with a Literal attribute. Crashes the initialisation of the module: Do you have an idea what I could be doing wrong here? |
|
The problem seems to come from the subclass check when we try to check if
the type of an annotation is a subclass of BaseModel. I've to dig into the
code to find the right way to fix this UC.
lmi
…On Wed, Dec 8, 2021 at 12:27 PM Alexandre Fayolle ***@***.***> wrote:
Hello @lmignon <https://github.com/lmignon> I'm testing pydantic on 15.0
using python 3.9. I get an error when I try to define a model with a
Literal attribute.
class Order(BaseModel):
warehouse: Literal["store", "olva", "spidy"]
# lots of things commented out
Crashes the initialisation of the module:
Traceback (most recent call last):
File "/odoo/src/odoo/service/server.py", line 1246, in preload_registries
registry = Registry.new(dbname, update_module=update_module)
File "/odoo/src/odoo/modules/registry.py", line 87, in new
odoo.modules.load_modules(registry, force_demo, status, update_module)
File "/odoo/src/odoo/modules/loading.py", line 581, in load_modules
model._register_hook()
File "/odoo/external-src/rest-framework/pydantic/builder.py", line 50, in _register_hook
self.build_registry(registry)
File "/odoo/external-src/rest-framework/pydantic/builder.py", line 83, in build_registry
registry.init_registry([m.name for m in graph])
File "/odoo/external-src/rest-framework/pydantic/registry.py", line 221, in init_registry
self.resolve_submodel_fields()
File "/odoo/external-src/rest-framework/pydantic/registry.py", line 176, in resolve_submodel_fields
cls._resolve_submodel_fields(registry=self)
File "/odoo/external-src/rest-framework/pydantic/models.py", line 185, in _resolve_submodel_fields
cls._resolve_submodel_field(field, registry)
File "/odoo/external-src/rest-framework/pydantic/models.py", line 196, in _resolve_submodel_field
if issubclass(field.type_, BaseModel):
File "/odoo/external-src/rest-framework/pydantic/models.py", line 154, in __subclasscheck__
return super().__subclasscheck__(subclass)
File "/usr/lib/python3.9/abc.py", line 102, in __subclasscheck__
return _abc_subclasscheck(cls, subclass)
TypeError: issubclass() arg 1 must be a class
Do you have an idea what I could be doing wrong here?
—
You are receiving this because you were mentioned.
Reply to this email directly, view it on GitHub
<#218 (comment)>,
or unsubscribe
<https://github.com/notifications/unsubscribe-auth/AAEE2WUTIPRPC2FVHYNKQU3UP46INANCNFSM5HRHTSKQ>
.
Triage notifications on the go with GitHub Mobile for iOS
<https://apps.apple.com/app/apple-store/id1477376905?ct=notification-email&mt=8&pt=524675>
or Android
<https://play.google.com/store/apps/details?id=com.github.android&referrer=utm_campaign%3Dnotification-email%26utm_medium%3Demail%26utm_source%3Dgithub>.
|
|
@gurneyalex The issue is fixed into my last commit. |
08e117a to
f6fa6e5
Compare
58b11a2 to
bfa2925
Compare
|
@lmignon another one that tricked me: I'm unable to call super() on a model which python-inherits from another model: when I call method() on DerivedModel, I get "TypeError: super(type, obj): obj must be an instance or subtype of type" Am I missing something? |
|
@gurneyalex I added a test for your UC but I'm not able to reproduce it. |
weird... I ended up calling the parent method in the old fashioned way |
@gurneyalex I reproduced the problem this weekend. It does not appear to be on py36 but on py38. It requires a lot of changes to solve it but I have the solution. As soon as I have some time, I will make the changes.
This way of doing bypass the expected class hierarchy build by odoo when resolving the dependency graph... |
|
Closing this PR since this functionality is now supported by the |
The marriage of the power of Pydantic and the modular approach of Odoo. And yes, it's possible to write modern python code within odoo 😏
Not yet fully tested in a project....