You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@pulsar.apache.org by "Joforde (via GitHub)" <gi...@apache.org> on 2025/06/23 12:50:15 UTC

[I] [Bug] REST API to produce messages to a single-partitioned topic fails with "Unable to add schema" error [pulsar]

Joforde opened a new issue, #24442:
URL: https://github.com/apache/pulsar/issues/24442

   ### Search before reporting
   
   - [x] I searched in the [issues](https://github.com/apache/pulsar/issues) and found nothing similar.
   
   
   ### Read release policy
   
   - [x] I understand that [unsupported versions](https://pulsar.apache.org/contribute/release-policy/#supported-versions) don't get bug fixes. I will attempt to reproduce the issue on a supported version of Pulsar client and Pulsar broker.
   
   
   ### User environment
   
   any released version
   
   ### Issue Description
   
   When using the REST API to produce messages to a single-partitioned topic (partition count = 1), the `topics.produceOnPersistentTopic` interface fails with "Unable to add schema" error due to incorrect topic type detection.
   
   ### Expected Behavior
   The REST API should successfully produce messages to single-partitioned topics, just like it works for non-partitioned topics and multi-partitioned topics.
   
   ### Actual Behavior
   The REST API fails to add schema to single-partitioned topics, preventing message production.
   
   ### Root Cause
   In `TopicsBase`, there's an incorrect condition for determining partitioned topics:
   
   ```java
   if (!topicName.isPartitioned() && metadata.partitions > 1) {
   ```
   
   This condition incorrectly treats single-partitioned topics (partition count = 1) as non-partitioned topics. The `topicName.isPartitioned()` method returns `false` for single-partitioned topics because they don't contain the `-partition-` suffix in their name, and `metadata.partitions > 1` is also `false` for single-partitioned topics.
   
   This leads to incorrect topic type detection, causing the schema addition logic to fail.
   
   
   ### Error messages
   
   ```text
   org.apache.pulsar.broker.service.schema.exceptions.SchemaException: Unable to add schema SchemaData(type=STRING, isDeleted=false, timestamp=1750682252591, user=Rest Producer, data=[], props={__charset=UTF-8}) to topic persistent://tenant/namespace/topic
   ```
   
   ### Reproducing the issue
   
   
   1. Create a partitioned topic with 1 partition:
      ```bash
      admin.topics().createPartitionedTopic("persistent://tenant/namespace/topic", 1);
      ```
   
   2. Try to produce messages using REST API:
      ```java
      ProducerMessages producerMessages = new ProducerMessages();
      producerMessages.setKeySchema(ObjectMapperFactory.getMapper().getObjectMapper().
          writeValueAsString(StringSchema.utf8().getSchemaInfo()));
      producerMessages.setValueSchema(ObjectMapperFactory.getMapper().getObjectMapper().
          writeValueAsString(StringSchema.utf8().getSchemaInfo()));
      // ... set messages
      topics.produceOnPersistentTopic(asyncResponse, tenant, namespace, topicName, false, producerMessages);
      ```
   
   3. The operation fails with:
      ```
      org.apache.pulsar.broker.service.schema.exceptions.SchemaException: Unable to add schema SchemaData(type=STRING, isDeleted=false, timestamp=1750682252591, user=Rest Producer, data=[], props={__charset=UTF-8}) to topic persistent://tenant/namespace/topic
      ```
   
   ### Additional information
   
   _No response_
   
   ### Are you willing to submit a PR?
   
   - [x] I'm willing to submit a PR!


-- 
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: commits-unsubscribe@pulsar.apache.org.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


Re: [I] [Bug] REST API to produce messages to a single-partitioned topic fails with "Unable to add schema" error [pulsar]

Posted by "Technoboy- (via GitHub)" <gi...@apache.org>.
Technoboy- closed issue #24442: [Bug] REST API to produce messages to a single-partitioned topic fails with "Unable to add schema" error
URL: https://github.com/apache/pulsar/issues/24442


-- 
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: commits-unsubscribe@pulsar.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


Re: [I] [Bug] REST API to produce messages to a single-partitioned topic fails with "Unable to add schema" error [pulsar]

Posted by "Joforde (via GitHub)" <gi...@apache.org>.
Joforde commented on issue #24442:
URL: https://github.com/apache/pulsar/issues/24442#issuecomment-2996502860

   https://github.com/Joforde/pulsar/commit/71ac9fe8325c3d7f74beeb8c0a734f0179860f3e


-- 
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: commits-unsubscribe@pulsar.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org