grishaf opened a new pull request, #304: URL: https://github.com/apache/pulsar-client-python/pull/304
## Motivation Currently the Python client cannot send null value messages, which are needed as tombstones on compacted topics to delete entries for specific keys. Attempting to call `producer.send(None, ...)` raises a `TypeError` because `BytesSchema.encode()` rejects `None`, and `_build_msg` has a second `_check_type(bytes, data, 'data')` guard. The C++ client added `MessageBuilder::setNullValue()` and `Message::hasNullValue()` in [apache/pulsar-client-cpp#563](https://github.com/apache/pulsar-client-cpp/pull/563) (merged April 3, 2026, milestone 4.2.0). The Java client has supported `value(null)` tombstones since v2.8+ via `TypedMessageBuilderImpl.beforeSend()` which sets `msgMetadata.setNullValue(true)` when the value is null. This PR wraps the new C++ API for Python, using the same pattern as the Java client. ## Modifications ### pybind11 bindings (`src/message.cc`) - Added `set_null_value` binding on `MessageBuilder` → `MessageBuilder::setNullValue()` - Added `has_null_value` binding on `Message` → `Message::hasNullValue()` ### Python wrapper (`pulsar/__init__.py`) - `Message.has_null_value()` — check if a received message is a tombstone - `Producer._build_msg()` — when `content is None`, skip schema encoding and call `mb.set_null_value()` instead of `mb.content(data)` (same pattern as Java's `beforeSend()`) - Updated `send()` and `send_async()` docstrings to document `None` content ### Dependencies (`dependencies.yaml`) - Bumped `pulsar-cpp` from `4.1.0` to `4.2.0` ### Tests (`tests/pulsar_test.py`) - `test_null_value_message` — send/receive null and non-null messages, verify `has_null_value()` - `test_null_value_vs_empty_bytes` — verify `b""` and `None` are distinct - `test_null_value_compaction` — tombstoned keys disappear after topic compaction - `test_null_value_table_view` — tombstoned keys removed from TableView - `test_null_value_with_properties` — properties survive on null-value messages ## Blocked on **This PR requires `pulsar-client-cpp` >= 4.2.0**, which has not been released yet (v4.1.0 is the latest as of May 2026). The `setNullValue()`/`hasNullValue()` APIs are merged into C++ `main` but not yet in a release. CI will not pass until 4.2.0 ships. References: - C++ issue: https://github.com/apache/pulsar-client-cpp/issues/489 - C++ PR: https://github.com/apache/pulsar-client-cpp/pull/563 Made with [Cursor](https://cursor.com) -- This is an automated message from the Apache Git Service. To respond to the message, please log on to GitHub and use the URL above to go to the specific comment. To unsubscribe, e-mail: [email protected] For queries about this service, please contact Infrastructure at: [email protected]
