This is an automated email from the ASF dual-hosted git repository.
potiuk pushed a commit to branch main
in repository https://gitbox.apache.org/repos/asf/airflow.git
The following commit(s) were added to refs/heads/main by this push:
new 48c210871c Continue on exception when retrieving metadata (#27665)
48c210871c is described below
commit 48c210871c4936167a99cb5dbadc9e0d05f11870
Author: Jarek Potiuk <[email protected]>
AuthorDate: Mon Nov 14 20:33:15 2022 +0100
Continue on exception when retrieving metadata (#27665)
There are cases where just retrieval of package metadata during
entrypoint discovery will cause an error (example
https://github.com/apache/airflow/discussions/27596).
In this case we should skip the package and continue discovery,
while logging a warning rather than crash.
---
airflow/utils/entry_points.py | 20 +++++++++++++-------
1 file changed, 13 insertions(+), 7 deletions(-)
diff --git a/airflow/utils/entry_points.py b/airflow/utils/entry_points.py
index da1431e533..41ea38845f 100644
--- a/airflow/utils/entry_points.py
+++ b/airflow/utils/entry_points.py
@@ -16,6 +16,7 @@
# under the License.
from __future__ import annotations
+import logging
from typing import Iterator
from packaging.utils import canonicalize_name
@@ -25,6 +26,8 @@ try:
except ImportError:
from importlib import metadata # type: ignore[no-redef]
+log = logging.getLogger(__name__)
+
def entry_points_with_dist(group: str) -> Iterator[tuple[metadata.EntryPoint,
metadata.Distribution]]:
"""Retrieve entry points of the given group.
@@ -37,11 +40,14 @@ def entry_points_with_dist(group: str) ->
Iterator[tuple[metadata.EntryPoint, me
"""
loaded: set[str] = set()
for dist in metadata.distributions():
- key = canonicalize_name(dist.metadata["Name"])
- if key in loaded:
- continue
- loaded.add(key)
- for e in dist.entry_points:
- if e.group != group:
+ try:
+ key = canonicalize_name(dist.metadata["Name"])
+ if key in loaded:
continue
- yield e, dist
+ loaded.add(key)
+ for e in dist.entry_points:
+ if e.group != group:
+ continue
+ yield e, dist
+ except Exception as e:
+ log.warning("Error when retrieving package metadata (skipping it):
%s, %s", dist, e)