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

Odoo Core Modules are not in the Remote Python interpreter. #152

Open
DaniilDigtyar opened this issue May 12, 2023 · 4 comments
Open

Odoo Core Modules are not in the Remote Python interpreter. #152

DaniilDigtyar opened this issue May 12, 2023 · 4 comments

Comments

@DaniilDigtyar
Copy link

DaniilDigtyar commented May 12, 2023

When using the remote python interpreter of the lxc container, some Odoo modules are not added by default to the venv.
Remote Python 3.7.7 (sftp://[email protected]:22/home/odoo/pyenv/versions/odoo/bin/python3.7)

All the modules located in /opt/odoo/addons these are all the core Odoo modules account, crm, l10n_es... are not added to the venv and not found by the interpreter because they are not installed via pip.

The modules located in /opt/odoo/odoo/addons, (base and all the testing modules) are added.

To fix this, I copy all the modules in /opt/odoo/addons to the /home/odoo/pyenv/versions/odoo/lib/python3.7/site-packages/odoo/addons folder.

Don't know I is something with my configuration that I do wrong, feedback is apreciated.

@DaniilDigtyar DaniilDigtyar changed the title Odoo Core Modules are not in the remote python interpreter. Odoo Core Modules are not in the Remote Python interpreter. May 12, 2023
@oyale
Copy link
Contributor

oyale commented Jul 13, 2023

Hey, Daniil!

Thanks for bringing this issue to our attention. I've been working to understand what's going on.

I discovered, just like you mentioned, that Odoo modules in /opt/odoo/addons aren't not present in the venv. I've also realized that this behavior isn't limited to an LXC container - it also occurs on a production server.

I noticed the same results when running these two scripts:

from odoo import modules
modules.get_modules()

and

import pkg_resources
installed_packages = pkg_resources.working_set
installed_packages_list = sorted(["%s==%s" % (i.key, i.version)
   for i in installed_packages])
print(installed_packages_list)
print(len(installed_packages_list))

using:

  • LXC /home/odoo/pyenv/versions/odoo/bin/python interpreter
  • LXC /home/odoo/pyenv/versions/odoo/bin/python3.8 interpreter
  • LXC python interpreter with the venv odoo loaded.
  • Remote LXC /home/odoo/pyenv/versions/odoo/bin/python interpreter via SSH (ssh debug.local -t "/home/odoo/pyenv/versions/odoo/bin/python -c '(...)'
  • The same of above in a non-containerized environment.

I am wondering if it is possible that this behavior is related to the fact that these modules, despite -or precisely because- they belong to Odoo core, are not straightforward available in a virtualenv, but through Odoo logic.

For instance, consider this example:

from odoo import models, fields, api
class InstanceCalendarEvent(models.Model):
    _inherit = 'calendar.event'

This returns an error, emphasizing that the import should start with 'odoo.addons'.:

    assert self.__module__.startswith('odoo.addons.'), \
AssertionError: Invalid import of __main__.InstanceCalendarEvent, it should start with 'odoo.addons'.

To help us get a handle on this, could you provide a little more information?

  • Why is this a problem? In which context do you need to access those modules?
  • What exact steps lead to the error?

I'm also intrigued about the use of the SFTP protocol. It's the only piece that it's unfamiliar to me.

Thanks again for reporting!!

Salut!

@DaniilDigtyar
Copy link
Author

Thanks for the answer.

The problem is not related to execution, odoo detects all the module even if they are not in the venv because we specify the two addons paths in the odoo.conf
addons_path = /opt/odoo_modules, /opt/odoo/addons

My problem is from the python interpreter, that only uses the modules found in the venv.

I use the IDE Pycharm, but it happens too in Visual Code, and when using this plugin it detects that these odoo core module are missing (when in execution they are not) and marks them as errors.

The SFTP protocol is how the IDE copies the venv locally to be able to use it.

I talked with other coopdevs employees, and it seems like I'm the only one that uses the remote interpreter or this plugin, because it assures me that I'm working in the exact same interpreter as the local lxc and makes suggestions and detects errors before I execute on the machine.

@oyale
Copy link
Contributor

oyale commented Jul 14, 2023

Ah! That sounds more familiar.

It seems more like a problem related to PyCharm/Odoo IDE configuration than with the odoo-role, doesn't it?

I've been taking a look at the Odoo IDE repository and I've seen some issues that might refer to a similar case. Have you asked there?

Regarding PyCharm, I can't remember the details right now, but it seems to me that there was a need to add/map folders for it to be aware of. For VsCode, I just documented how to use it for debugging in devenv yesterday, and it seems to work like a charm.

I believe that the fact that these addons are not directly available under the interpreter is the expected behavior.

Maybe you could give SSH a shot, using PyCharm's Remote Development feature?

@oyale
Copy link
Contributor

oyale commented Aug 2, 2023

Hey, @DaniilDigtyar, how did it go? Did the documentation help you?

Do you agree that this isn't a problem from odoo-role and, thus, this issue can be closed?

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

No branches or pull requests

2 participants