Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 5 additions & 4 deletions .github/workflows/main.yml
Original file line number Diff line number Diff line change
Expand Up @@ -7,16 +7,17 @@ jobs:
lint:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
- uses: actions/checkout@v7.0.0
- name: Setup Python
uses: actions/setup-python@v5
uses: actions/setup-python@v6.3.0
with:
python-version: '3.12'
cache: 'pip'
cache-dependency-path: 'requirements/*.txt'
- name: Install dev dependencies
run: python -m pip install -r requirements/dev.txt
- name: Run linting
continue-on-error: true
run: python -m tox -e lint,mypy,mypy-samples-image,mypy-samples-json

test:
Expand All @@ -26,9 +27,9 @@ jobs:
os: [ubuntu-latest, windows-latest, macos-latest]
runs-on: ${{ matrix.os }}
steps:
- uses: actions/checkout@v4
- uses: actions/checkout@v7.0.0
- name: Setup Python
uses: actions/setup-python@v5
uses: actions/setup-python@v6.3.0
with:
python-version: ${{ matrix.python }}
cache: 'pip'
Expand Down
10 changes: 5 additions & 5 deletions .github/workflows/pypi-release.yml
Original file line number Diff line number Diff line change
Expand Up @@ -12,14 +12,14 @@ jobs:
name: Build source distribution
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
- uses: actions/checkout@v7.0.0
with:
fetch-depth: 0

- name: Build SDist and wheel
run: pipx run build

- uses: actions/upload-artifact@v4
- uses: actions/upload-artifact@v7.0.1
with:
name: artifact
path: dist/*
Expand All @@ -31,17 +31,17 @@ jobs:
if: github.event_name == 'push'
needs: [ build_dist ]
steps:
- uses: actions/checkout@v4
- uses: actions/checkout@v7.0.0
with:
fetch-depth: 0
- name: Set up Python
uses: actions/setup-python@v5
uses: actions/setup-python@v6.3.0
with:
python-version: "3.12"
cache: 'pip'
- name: Install build dependencies
run: pip install -U setuptools wheel build
- uses: actions/download-artifact@v4
- uses: actions/download-artifact@v8.0.1
with:
# unpacks default artifact into dist/
# if `name: artifact` is omitted, the action will create extra parent dir
Expand Down
7 changes: 7 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,12 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0

## [Unreleased]

## [1.13.0]

### Fixed
- Kafka `to_structured` converter dropping `datacontentype` attribute
when setting a header. ([#296])

## [1.12.1]

### Changed
Expand Down Expand Up @@ -310,3 +316,4 @@ CloudEvents v2 is a rewrite with ongoing development ([#271])
[#248]: https://github.com/cloudevents/sdk-python/pull/248
[#249]: https://github.com/cloudevents/sdk-python/pull/249
[#271]: https://github.com/cloudevents/sdk-python/pull/271
[#296]: https://github.com/cloudevents/sdk-python/pull/296
2 changes: 1 addition & 1 deletion cloudevents/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,4 +12,4 @@
# License for the specific language governing permissions and limitations
# under the License.

__version__ = "1.12.1"
__version__ = "1.13.0"
5 changes: 3 additions & 2 deletions cloudevents/kafka/conversion.py
Original file line number Diff line number Diff line change
Expand Up @@ -213,8 +213,9 @@ def to_structured(
attrs["data"] = data

headers = {}
if "datacontenttype" in attrs:
headers["content-type"] = attrs.pop("datacontenttype").encode("utf-8")
datacontenttype = attrs.get("datacontenttype")
if datacontenttype is not None:
headers["content-type"] = datacontenttype.encode("utf-8")

try:
value = envelope_marshaller(attrs)
Expand Down
11 changes: 11 additions & 0 deletions cloudevents/tests/test_kafka_conversions.py
Original file line number Diff line number Diff line change
Expand Up @@ -247,6 +247,7 @@ def test_sets_value_default_marshallers(self, source_event):
"source": source_event["source"],
"type": source_event["type"],
"time": source_event["time"],
"datacontenttype": source_event["datacontenttype"],
"partitionkey": source_event["partitionkey"],
"data": self.expected_data,
}
Expand All @@ -263,6 +264,7 @@ def test_sets_value_custom_data_marshaller_default_envelope(
"source": source_event["source"],
"type": source_event["type"],
"time": source_event["time"],
"datacontenttype": source_event["datacontenttype"],
"partitionkey": source_event["partitionkey"],
"data_base64": base64.b64encode(
custom_marshaller(self.expected_data)
Expand All @@ -281,6 +283,7 @@ def test_sets_value_custom_envelope_marshaller(
"source": source_event["source"],
"type": source_event["type"],
"time": source_event["time"],
"datacontenttype": source_event["datacontenttype"],
"partitionkey": source_event["partitionkey"],
"data": self.expected_data,
}
Expand All @@ -299,6 +302,7 @@ def test_sets_value_custom_marshallers(self, source_event, custom_marshaller):
"source": source_event["source"],
"type": source_event["type"],
"time": source_event["time"],
"datacontenttype": source_event["datacontenttype"],
"partitionkey": source_event["partitionkey"],
"data_base64": base64.b64encode(
custom_marshaller(self.expected_data)
Expand Down Expand Up @@ -335,6 +339,13 @@ def test_sets_headers(self, source_event):
"utf-8"
)

def test_datacontenttype_attribute_present_after_setting_header(self, source_event):
result = to_structured(source_event)
datacontenttype = source_event.get("datacontenttype")
assert len(result.headers) == 1
assert result.headers["content-type"] == datacontenttype.encode("utf-8")
assert datacontenttype in result.value.decode("utf-8")

def test_datamarshaller_exception(self, source_event):
with pytest.raises(cloud_exceptions.DataMarshallerError):
to_structured(source_event, data_marshaller=failing_func)
Expand Down
Loading