From cbfa1864a1b14be65999367116f55b03610dbe21 Mon Sep 17 00:00:00 2001 From: Jacopo Farina Date: Mon, 9 Dec 2024 15:34:18 +0100 Subject: [PATCH 1/4] Show raw returned value in case JSON decoding fails --- kafka_schema_registry/__init__.py | 10 ++++++++-- requirements-dev.txt | 12 ++++++------ requirements.txt | 4 ++-- 3 files changed, 16 insertions(+), 10 deletions(-) diff --git a/kafka_schema_registry/__init__.py b/kafka_schema_registry/__init__.py index bae3f41..60f4b37 100644 --- a/kafka_schema_registry/__init__.py +++ b/kafka_schema_registry/__init__.py @@ -10,6 +10,7 @@ from kafka.admin import NewTopic from kafka.errors import TopicAlreadyExistsError, NoBrokersAvailable from requests import request +from request.exceptions import JSONDecodeError logger = logging.getLogger(__name__) @@ -86,9 +87,14 @@ def publish_schemas( 'Content-Type': 'application/json' } ) - if 'id' not in value_resp.json(): + try: + obj = value_resp.json() + except json.JSONDecodeError: + logger.error(f'Error decoding response: {value_resp.text}') + raise + if 'id' not in obj: logger.error(f'No id in response: {value_resp.json()}') - value_schema_id = value_resp.json()['id'] + value_schema_id = obj['id'] key_schema_id = None if key_schema is not None: diff --git a/requirements-dev.txt b/requirements-dev.txt index 0d7066b..9923f15 100644 --- a/requirements-dev.txt +++ b/requirements-dev.txt @@ -1,7 +1,7 @@ -pytest==6.2.5 -pytest-cov==3.0.0 -flake8==4.0.1 -responses==0.17.0 -twine==3.7.1 -wheel==0.37.1 +pytest==8.3.4 +pytest-cov==6.0.0 +flake8==7.1.1 +responses==0.25.3 +twine==6.0.1 +wheel==0.45.1 diff --git a/requirements.txt b/requirements.txt index 21c60b8..42ea387 100644 --- a/requirements.txt +++ b/requirements.txt @@ -1,3 +1,3 @@ -fastavro==1.4.9 +fastavro==1.9.7 kafka-python==2.0.2 -requests==2.27.1 +requests==2.32.3 From 3c75ea304607378e7128fceff7762c7034828889 Mon Sep 17 00:00:00 2001 From: Jacopo Farina Date: Mon, 9 Dec 2024 15:41:10 +0100 Subject: [PATCH 2/4] Update the GH action, it was 2 years old --- .github/workflows/python-package.yaml | 5 +++-- kafka_schema_registry/__init__.py | 2 +- setup.py | 2 +- 3 files changed, 5 insertions(+), 4 deletions(-) diff --git a/.github/workflows/python-package.yaml b/.github/workflows/python-package.yaml index 8cb1029..4f32ab5 100644 --- a/.github/workflows/python-package.yaml +++ b/.github/workflows/python-package.yaml @@ -13,10 +13,11 @@ jobs: fail-fast: false matrix: python-version: - - "3.7" - - "3.8" - "3.9" - "3.10" + - "3.11" + - "3.12" + steps: - uses: actions/checkout@v2 diff --git a/kafka_schema_registry/__init__.py b/kafka_schema_registry/__init__.py index 60f4b37..75b6dea 100644 --- a/kafka_schema_registry/__init__.py +++ b/kafka_schema_registry/__init__.py @@ -10,7 +10,7 @@ from kafka.admin import NewTopic from kafka.errors import TopicAlreadyExistsError, NoBrokersAvailable from requests import request -from request.exceptions import JSONDecodeError +from requests.exceptions import JSONDecodeError logger = logging.getLogger(__name__) diff --git a/setup.py b/setup.py index 84978ac..c4ddda2 100644 --- a/setup.py +++ b/setup.py @@ -19,7 +19,7 @@ "Changelog": "https://github.com/flix-tech/kafka-schema-registry/blob/master/CHANGELOG.md", # noqa "Source": 'https://github.com/flix-tech/kafka-schema-registry', }, - python_requires='>=3.7', + python_requires='>=3.9', install_requires=[ 'fastavro', 'kafka-python', From 12caf01dddf30f4a851e7972c0b1803413802028 Mon Sep 17 00:00:00 2001 From: Jacopo Farina Date: Mon, 9 Dec 2024 15:43:20 +0100 Subject: [PATCH 3/4] Dectect exception on requests own JSON class, not stdlib JSON --- kafka_schema_registry/__init__.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/kafka_schema_registry/__init__.py b/kafka_schema_registry/__init__.py index 75b6dea..f8a2fa7 100644 --- a/kafka_schema_registry/__init__.py +++ b/kafka_schema_registry/__init__.py @@ -89,7 +89,7 @@ def publish_schemas( ) try: obj = value_resp.json() - except json.JSONDecodeError: + except JSONDecodeError: logger.error(f'Error decoding response: {value_resp.text}') raise if 'id' not in obj: From 10090cbca9ee83fd2734b811084c20973e0b157c Mon Sep 17 00:00:00 2001 From: Jacopo Farina Date: Mon, 9 Dec 2024 15:50:55 +0100 Subject: [PATCH 4/4] Switch to kafka-python-ng --- README.md | 2 +- requirements.txt | 2 +- setup.py | 2 +- 3 files changed, 3 insertions(+), 3 deletions(-) diff --git a/README.md b/README.md index 02d1e78..f164420 100644 --- a/README.md +++ b/README.md @@ -10,7 +10,7 @@ It takes care of: It works with [kafka-python][], and extra arguments are forwarded to it. -[kafka-python]: https://github.com/dpkp/kafka-python +[kafka-python]: https://github.com/wbarnha/kafka-python-ng ## Installing diff --git a/requirements.txt b/requirements.txt index 42ea387..688223d 100644 --- a/requirements.txt +++ b/requirements.txt @@ -1,3 +1,3 @@ fastavro==1.9.7 -kafka-python==2.0.2 +kafka-python-ng==2.2.3 requests==2.32.3 diff --git a/setup.py b/setup.py index c4ddda2..ec702dd 100644 --- a/setup.py +++ b/setup.py @@ -22,7 +22,7 @@ python_requires='>=3.9', install_requires=[ 'fastavro', - 'kafka-python', + 'kafka-python-ng', 'requests', ], packages=['kafka_schema_registry'],