From a6dbecc17af21569709568121e8a92a5cdff6fa2 Mon Sep 17 00:00:00 2001 From: Dominique Dumont Date: Thu, 6 Aug 2026 13:58:59 +0200 Subject: [PATCH] Fix cloudevents import in Python code This commit fixes the following error seen when building ML-sentiment-analysis: ---> Running application from script (app.sh) ... ERROR:root:Function must export either 'new' or 'handle' Traceback (most recent call last): File "/opt/app-root/src/.func/build/service/main.py", line 13, in from function import new as handler # type: ignore[import] ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ File "/opt/app-root/lib64/python3.11/site-packages/function/__init__.py", line 1, in from .func import new File "/opt/app-root/lib64/python3.11/site-packages/function/func.py", line 2, in from cloudevents.http import CloudEvent ModuleNotFoundError: No module named 'cloudevents.http' Python doc (https://pypi.org/project/cloudevents/) mentions that CloudEvent is imported with: from cloudevents.core.v1.event import CloudEvent Even though I've modified all occurrences of "import CloudEvent", I've tested this change only on ML-sentiment-analysis --- .../solution/ML-bad-word-filter/function/func.py | 2 +- .../solution/ML-bad-word-filter/tests/test_func.py | 2 +- .../solution/ML-sentiment-analysis/function/func.py | 2 +- .../solution/ML-sentiment-analysis/tests/test_func.py | 2 +- docs/blog/articles/ai_functions_llama_stack.md | 2 +- .../page-2/sentiment-analysis-service-for-bookstore-reviews.md | 2 +- .../bookstore/page-3/create-bad-word-filter-service.md | 2 +- 7 files changed, 7 insertions(+), 7 deletions(-) diff --git a/code-samples/eventing/bookstore-sample-app/solution/ML-bad-word-filter/function/func.py b/code-samples/eventing/bookstore-sample-app/solution/ML-bad-word-filter/function/func.py index f0ead6c886a..490a2f5e3e4 100644 --- a/code-samples/eventing/bookstore-sample-app/solution/ML-bad-word-filter/function/func.py +++ b/code-samples/eventing/bookstore-sample-app/solution/ML-bad-word-filter/function/func.py @@ -1,5 +1,5 @@ import logging -from cloudevents.http import CloudEvent +from cloudevents.core.v1.event import CloudEvent from profanity_check import predict def new(): diff --git a/code-samples/eventing/bookstore-sample-app/solution/ML-bad-word-filter/tests/test_func.py b/code-samples/eventing/bookstore-sample-app/solution/ML-bad-word-filter/tests/test_func.py index ad126f72302..dccc98c50df 100644 --- a/code-samples/eventing/bookstore-sample-app/solution/ML-bad-word-filter/tests/test_func.py +++ b/code-samples/eventing/bookstore-sample-app/solution/ML-bad-word-filter/tests/test_func.py @@ -10,7 +10,7 @@ import json import asyncio import pytest -from cloudevents.http import CloudEvent +from cloudevents.core.v1.event import CloudEvent from function import new diff --git a/code-samples/eventing/bookstore-sample-app/solution/ML-sentiment-analysis/function/func.py b/code-samples/eventing/bookstore-sample-app/solution/ML-sentiment-analysis/function/func.py index 8ed46f20b69..5c9dd3774dc 100644 --- a/code-samples/eventing/bookstore-sample-app/solution/ML-sentiment-analysis/function/func.py +++ b/code-samples/eventing/bookstore-sample-app/solution/ML-sentiment-analysis/function/func.py @@ -1,5 +1,5 @@ import logging -from cloudevents.http import CloudEvent +from cloudevents.core.v1.event import CloudEvent from textblob import TextBlob import textblob diff --git a/code-samples/eventing/bookstore-sample-app/solution/ML-sentiment-analysis/tests/test_func.py b/code-samples/eventing/bookstore-sample-app/solution/ML-sentiment-analysis/tests/test_func.py index ad126f72302..dccc98c50df 100644 --- a/code-samples/eventing/bookstore-sample-app/solution/ML-sentiment-analysis/tests/test_func.py +++ b/code-samples/eventing/bookstore-sample-app/solution/ML-sentiment-analysis/tests/test_func.py @@ -10,7 +10,7 @@ import json import asyncio import pytest -from cloudevents.http import CloudEvent +from cloudevents.core.v1.event import CloudEvent from function import new diff --git a/docs/blog/articles/ai_functions_llama_stack.md b/docs/blog/articles/ai_functions_llama_stack.md index 37f8c385bd1..9ef08afaa9e 100644 --- a/docs/blog/articles/ai_functions_llama_stack.md +++ b/docs/blog/articles/ai_functions_llama_stack.md @@ -141,7 +141,7 @@ See the entire code: # Function import logging import os -from cloudevents.http import CloudEvent +from cloudevents.core.v1.event import CloudEvent from llama_stack_client import LlamaStackClient def new(): diff --git a/docs/versioned/bookstore/page-2/sentiment-analysis-service-for-bookstore-reviews.md b/docs/versioned/bookstore/page-2/sentiment-analysis-service-for-bookstore-reviews.md index 88a535b8940..5c6fadf8d42 100644 --- a/docs/versioned/bookstore/page-2/sentiment-analysis-service-for-bookstore-reviews.md +++ b/docs/versioned/bookstore/page-2/sentiment-analysis-service-for-bookstore-reviews.md @@ -114,7 +114,7 @@ You can replace the generated code with the sentiment analysis logic. You can us ```python import logging - from cloudevents.http import CloudEvent + from cloudevents.core.v1.event import CloudEvent from textblob import TextBlob def new(): diff --git a/docs/versioned/bookstore/page-3/create-bad-word-filter-service.md b/docs/versioned/bookstore/page-3/create-bad-word-filter-service.md index e86704e6cfa..d24c7e4c34e 100644 --- a/docs/versioned/bookstore/page-3/create-bad-word-filter-service.md +++ b/docs/versioned/bookstore/page-3/create-bad-word-filter-service.md @@ -82,7 +82,7 @@ func create -l python bad-word-filter -t cloudevents ```python import logging - from cloudevents.http import CloudEvent + from cloudevents.core.v1.event import CloudEvent from profanity_check import predict def new():