Skip to content
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

[16.0] extendable classes not loaded in registry #463

Open
antonioburic opened this issue Oct 10, 2024 · 0 comments
Open

[16.0] extendable classes not loaded in registry #463

antonioburic opened this issue Oct 10, 2024 · 0 comments
Labels
bug Something isn't working

Comments

@antonioburic
Copy link
Member

antonioburic commented Oct 10, 2024

Module

extendable

Describe the bug

We have a custom module that defines pydantic models using ExtendableBaseModel from extendable_pydantic
An example:

from extendable_pydantic import ExtendableBaseModel
from pydantic import ConfigDict

from odoo.addons.fastapi.dependencies import (
    authenticated_partner,
    odoo_env,
)


class ResPartnerResponse(ExtendableBaseModel, revalidate_instances='always'):
    partner_id: int
    partner_shipping_id: int
    partner_invoice_id: int

    model_config = ConfigDict(from_attributes=True)

The endpoint is defined as below:

@main_api_router.post(
    '/res.partner',
    dependencies=[Depends(authenticated_partner)],
    tags=['res.partner'],
    response_model=ResPartnerResponse,
    response_model_exclude_none=True,
)
def post_res_partner_create_search(
...

this is defined in a custom module at the following path: custom_module/models/pydantic_models/res_partner.py

upon trying to install the module from the UI (once the modules have been loaded already) there is an error when trying to load the module, traceback below:

  File "/home/antonio/dev/project/custom_module/models/pydantic_models/res_partner.py", line 69, in <module>
    @main_api_router.post(
     ^^^^^^^^^^^^^^^^^^^^^
  File "/home/antonio/.pyenv/versions/3.11.9/envs/project_name/lib/python3.11/site-packages/fastapi/routing.py", line 972, in decorator
    self.add_api_route(
  File "/home/antonio/.pyenv/versions/3.11.9/envs/project_name/lib/python3.11/site-packages/fastapi/routing.py", line 911, in add_api_route
    route = route_class(
            ^^^^^^^^^^^^
  File "/home/antonio/.pyenv/versions/3.11.9/envs/project_name/lib/python3.11/site-packages/fastapi/routing.py", line 500, in __init__
    self.response_field = create_model_field(
                          ^^^^^^^^^^^^^^^^^^^
  File "/home/antonio/.pyenv/versions/3.11.9/envs/project_name/lib/python3.11/site-packages/extendable_pydantic/_patch.py", line 66, in _create_response_field_wrapper
    _resolve_model_fields_annotation([field])
  File "/home/antonio/.pyenv/versions/3.11.9/envs/project_name/lib/python3.11/site-packages/extendable_pydantic/_patch.py", line 30, in _resolve_model_fields_annotation
    new_type = resolve_annotation(field_info.annotation)
               ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/home/antonio/.pyenv/versions/3.11.9/envs/project_name/lib/python3.11/site-packages/extendable_pydantic/utils.py", line 116, in resolve_annotation
    final_type = type_._get_assembled_cls(registry)
                 ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/home/antonio/.pyenv/versions/3.11.9/envs/project_name/lib/python3.11/site-packages/extendable/main.py", line 274, in _get_assembled_cls
    return registry[cls.__xreg_name__]
           ~~~~~~~~^^^^^^^^^^^^^^^^^^^
  File "/home/antonio/.pyenv/versions/3.11.9/envs/project_name/lib/python3.11/site-packages/extendable/registry.py", line 49, in __getitem__
    return self._extendable_classes[key]
           ~~~~~~~~~~~~~~~~~~~~~~~~^^^^^
KeyError: 'odoo.addons.custom_module.models.pydantic_models.res_partner.ResPartnerResponse'

This isn't the case when the module is being installed using a CLI (using -i custom_module), only when the module install/upgrade gets triggered in the UI.

To Reproduce

Affected versions: 16.0

Steps to reproduce the behavior:

  1. defining an extendable model as above
  2. trying to install the module in the UI (after the modules have been loaded already, not via the CLI)

Expected behavior
The module can be installed with extendable pydantic models using ExtendableBaseModel.

library versions:
extendable==1.2.2
extendable_pydantic==1.3.2

@antonioburic antonioburic added the bug Something isn't working label Oct 10, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

No branches or pull requests

1 participant