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: [email protected] For queries about this service, please contact Infrastructure at: [email protected]
