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

Cannot import module with callback #364

Open
mfocko opened this issue May 27, 2024 · 1 comment
Open

Cannot import module with callback #364

mfocko opened this issue May 27, 2024 · 1 comment

Comments

@mfocko
Copy link
Contributor

mfocko commented May 27, 2024

Hi, during today's production deployment (packit/agile#552) of Packit Service I hit multiple issues with the Fedora Messaging.

Missing requests

The easiest one to fix (at least I hope) is missing requests dependency for the new replay feature. I have a feeling that this is related to the way it's being packaged into RPM, so right now the requests doesn't get installed. I've installed manually on our side as of now and hopefully will open a PR that will fix this.

Failing import

Right now (Fedora Messaging 3.5.0 from RPM) I'm getting:

Error: Failed to import the callback module (No module named 'packit_service_fedmsg') provided in the --callback argument

The way we build the image can be seen here.

I was trying to debug this issue:

  1. I can import the module from python3 REPL in the image

  2. I can import using your own function _callback_from_python_path():

    mfocko@ampere main*​​ ≡
    packit-service-fedmsg % podman run --rm -ti quay.io/packit/packit-service-fedmsg:dev python3
    Python 3.9.18 (main, Jan 24 2024, 00:00:00) 
    [GCC 11.4.1 20231218 (Red Hat 11.4.1-3)] on linux
    Type "help", "copyright", "credits" or "license" for more information.
    >>> from fedora_messaging.cli import _callback_from_python_path
    /usr/lib/python3.9/site-packages/requests/__init__.py:87: RequestsDependencyWarning: urllib3 (2.2.1) or chardet (4.0.0) doesn't match a supported version!
      warnings.warn("urllib3 ({}) or chardet ({}) doesn't match a supported "
    >>> m = _callback_from_python_path("packit_service_fedmsg.consumer:Consumerino")
    [INFO fedora_messaging.cli] Starting consumer with packit_service_fedmsg.consumer:Consumerino callback
    >>> 
    
  3. This bug has been introduced in between 3.4.1 (works as intended) and 3.5.0 releases.

    I've briefly went through the commits in between those tags, checked the git blame on the cli.py for any changes of importing the callbacks, haven't managed to find anything suspicious.

Additional information

  • Base image for container: C9S
  • Source of Fedora Messaging: RPM from EPEL
mfocko added a commit to mfocko/fedora-messaging that referenced this issue May 27, 2024
@mfocko
Copy link
Contributor Author

mfocko commented May 28, 2024

Upon closer inspection and discussion with @nforro, it appears that the issue comes from the fact that we do global pip install from the sources which installs to /usr/local/ and it's missing in the sys.path, while it's being present when running the Python REPL.

mfocko added a commit to mfocko/packit-service-fedmsg that referenced this issue May 30, 2024
With regards to the change that occured in between 3.4.1 and 3.5.0
releases of Fedora Messaging, it is not possible to import consumer
callback from ‹/usr/local/› installed Python module, which is the
default for global installation of packages via pip.

Given the fact that there needs to be hardcoded Python version in the
path, I hate this solution.

When trying out ‹--callback-file›, I've been hit with the same import
issue, as Celery is installed via pip too, cause it hasn't been released
to EPEL9 even after a year of requesting this via RHBZ#2032543.

Trying out the “hack”¹ from similar project resulted in failure too, as
the current working directory isn't included in the path either.

So much for the ecosystem and easy to use…

¹ https://gitlab.com/CentOS/Integration/gitlab-webhooks/-/merge_requests/1/diffs?commit_id=1bc3b2f8c2598dd6a24c70f149b3cc683eaf37b1

Related to fedora-infra/fedora-messaging#364

Signed-off-by: Matej Focko <[email protected]>
mfocko added a commit to mfocko/packit-service-fedmsg that referenced this issue May 30, 2024
With regards to the change that occured in between 3.4.1 and 3.5.0
releases of Fedora Messaging, it is not possible to import consumer
callback from ‹/usr/local/› installed Python module, which is the
default for global installation of packages via pip.

Given the fact that there needs to be hardcoded Python version in the
path, I hate this solution.

When trying out ‹--callback-file›, I've been hit with the same import
issue, as Celery is installed via pip too, cause it hasn't been released
to EPEL9 even after a year of requesting this via RHBZ#2032543.

Trying out the “hack”¹ from similar project resulted in failure too, as
the current working directory isn't included in the path either.

So much for the ecosystem and easy to use…

¹ https://gitlab.com/CentOS/Integration/gitlab-webhooks/-/merge_requests/1/diffs?commit_id=1bc3b2f8c2598dd6a24c70f149b3cc683eaf37b1

Related to fedora-infra/fedora-messaging#364

Signed-off-by: Matej Focko <[email protected]>
softwarefactory-project-zuul bot added a commit to packit/packit-service-fedmsg that referenced this issue May 30, 2024
fix: add ‹/usr/local› to ‹PYTHONPATH›

With regards to the change that occured in between 3.4.1 and 3.5.0 releases of Fedora Messaging, it is not possible to import consumer callback from ‹/usr/local/› installed Python module, which is the default for global installation of packages via pip.
Given the fact that there needs to be hardcoded Python version in the path, I hate this solution.
When trying out ‹--callback-file›, I've been hit with the same import issue, as Celery is installed via pip too, cause it hasn't been released to EPEL9 even after a year of requesting this via RHBZ#2032543.
Trying out the “hack”¹ from similar project resulted in failure too, as the current working directory isn't included in the path either.
So much for the ecosystem and easy to use…
¹ https://gitlab.com/CentOS/Integration/gitlab-webhooks/-/merge_requests/1/diffs?commit_id=1bc3b2f8c2598dd6a24c70f149b3cc683eaf37b1
Related to fedora-infra/fedora-messaging#364



follow-up from the Monday's deployment

Reviewed-by: Nikola Forró
Reviewed-by: Laura Barcziová
Reviewed-by: Matej Focko
mfocko added a commit to mfocko/fedora-messaging that referenced this issue Jun 12, 2024
abompard pushed a commit that referenced this issue Jun 13, 2024
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

1 participant