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

[FIX] Using Optional from typing instead of | operation #498

Open
wants to merge 2 commits into
base: 16.0
Choose a base branch
from

Conversation

nhatnm0612
Copy link

Context:

  • I got a dockerfile like:
FROM odoo:16.0

USER root

COPY ./rest-framework /mnt/extra-addons/rest-framework

COPY ./server-auth /mnt/extra-addons/server-auth

COPY ./web-api /mnt/extra-addons/web-api

RUN apt-get update && apt-get install -y python3-pip

RUN python3 -m pip install --upgrade pip

RUN pip install -r /mnt/extra-addons/rest-framework/requirements.txt

RUN pip install -r /mnt/extra-addons/server-auth/requirements.txt

RUN pip install -r /mnt/extra-addons/web-api/requirements.txt

USER odoo
  • Build docker image from file, running image as an Odoo container

  • Install FastAPI module and meet an error:

RPC_ERROR
Odoo Server Error
Traceback (most recent call last):
  File "/usr/lib/python3/dist-packages/odoo/http.py", line 1658, in _serve_db
    return service_model.retrying(self._serve_ir_http, self.env)
  File "/usr/lib/python3/dist-packages/odoo/service/model.py", line 133, in retrying
    result = func()
  File "/usr/lib/python3/dist-packages/odoo/http.py", line 1686, in _serve_ir_http
    response = self.dispatcher.dispatch(rule.endpoint, args)
  File "/usr/lib/python3/dist-packages/odoo/http.py", line 1890, in dispatch
    result = self.request.registry['ir.http']._dispatch(endpoint)
  File "/usr/lib/python3/dist-packages/odoo/addons/base/models/ir_http.py", line 154, in _dispatch
    result = endpoint(**request.params)
  File "/usr/lib/python3/dist-packages/odoo/http.py", line 734, in route_wrapper
    result = endpoint(self, *args, **params_ok)
  File "/usr/lib/python3/dist-packages/odoo/addons/web/controllers/dataset.py", line 46, in call_button
    action = self._call_kw(model, method, args, kwargs)
  File "/usr/lib/python3/dist-packages/odoo/addons/web/controllers/dataset.py", line 33, in _call_kw
    return call_kw(request.env[model], method, args, kwargs)
  File "/usr/lib/python3/dist-packages/odoo/api.py", line 468, in call_kw
    result = _call_kw_multi(method, model, args, kwargs)
  File "/usr/lib/python3/dist-packages/odoo/api.py", line 453, in _call_kw_multi
    result = method(recs, *args, **kwargs)
  File "<decorator-gen-77>", line 2, in button_immediate_install
  File "/usr/lib/python3/dist-packages/odoo/addons/base/models/ir_module.py", line 74, in check_and_log
    return method(self, *args, **kwargs)
  File "/usr/lib/python3/dist-packages/odoo/addons/base/models/ir_module.py", line 478, in button_immediate_install
    return self._button_immediate_function(self.env.registry[self._name].button_install)
  File "/usr/lib/python3/dist-packages/odoo/addons/base/models/ir_module.py", line 602, in _button_immediate_function
    registry = modules.registry.Registry.new(self._cr.dbname, update_module=True)
  File "<decorator-gen-16>", line 2, in new
  File "/usr/lib/python3/dist-packages/odoo/tools/func.py", line 87, in locked
    return func(inst, *args, **kwargs)
  File "/usr/lib/python3/dist-packages/odoo/modules/registry.py", line 87, in new
    odoo.modules.load_modules(registry, force_demo, status, update_module)
  File "/usr/lib/python3/dist-packages/odoo/modules/loading.py", line 489, in load_modules
    processed_modules += load_marked_modules(cr, graph,
  File "/usr/lib/python3/dist-packages/odoo/modules/loading.py", line 373, in load_marked_modules
    loaded, processed = load_module_graph(
  File "/usr/lib/python3/dist-packages/odoo/modules/loading.py", line 189, in load_module_graph
    load_openerp_module(package.name)
  File "/usr/lib/python3/dist-packages/odoo/modules/module.py", line 471, in load_openerp_module
    __import__('odoo.addons.' + module_name)
  File "/mnt/extra-addons/rest-framework/fastapi/__init__.py", line 1, in <module>
    from . import models
  File "/mnt/extra-addons/rest-framework/fastapi/models/__init__.py", line 1, in <module>
    from .fastapi_endpoint import FastapiEndpoint
  File "/mnt/extra-addons/rest-framework/fastapi/models/fastapi_endpoint.py", line 17, in <module>
    from .. import dependencies
  File "/mnt/extra-addons/rest-framework/fastapi/dependencies.py", line 22, in <module>
    def company_id() -> int | None:
TypeError: unsupported operand type(s) for |: 'type' and 'NoneType'

The above server error caused the following client error:
RPC_ERROR: Odoo Server Error
    RPCError@http://localhost/web/assets/22-6b01176/web.assets_backend.min.js:998:274
    makeErrorFromResponse@http://localhost/web/assets/22-6b01176/web.assets_backend.min.js:1002:163
    jsonrpc/promise</<@http://localhost/web/assets/22-6b01176/web.assets_backend.min.js:1010:34
    

Reason

turn outs, Odoo:16.0 container is using Python 3.9.2 where | operand is not yet working

$ python3 --version
Python 3.9.2

Fix

instead of using something like:

... -> int | None

we should use something like:

from typing import Optional

... -> Optional[int]

for python 3.9 compatible

@OCA-git-bot
Copy link
Contributor

Hi @lmignon,
some modules you are maintaining are being modified, check this out!

Copy link
Contributor

@lmignon lmignon left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hi @nhatnm0612,

Thank you for your proposal. Nevertheless, we decided to only support python >= 3.10 since our CI and the one from Odoo uses this version of python.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants