Skip to content

API usability: defaultNumPartitions validation is too strict for non-partitioned topic type #24998

Closed

Description

@Shawyeok

Problem Description

When setting autoTopicCreation on namespace policy, the API validation prevents setting defaultNumPartitions when the topic type is non-partitioned. This limitation makes the API harder to use and less flexible.

Current behavior:

  • Setting defaultNumPartitions with topicType="non-partitioned" results in a validation error: "[defaultNumPartitions] is not allowed to be set when the type is non-partition."

Code location:

} else if (TopicType.NON_PARTITIONED.toString().equals(override.getTopicType())) {
if (override.getDefaultNumPartitions() != null) {
return ValidateResult.fail("[defaultNumPartitions] is not allowed to be"
+ " set when the type is non-partition.");
}
}

Use Cases Affected

  1. Configuration management: Users managing configurations programmatically or via infrastructure-as-code tools may want to set a default value even for non-partitioned topics, especially if they plan to switch to partitioned topics later.

  2. API consistency: The validation requires users to conditionally include/exclude the defaultNumPartitions field based on topic type, making the API less consistent and more error-prone.

  3. Configuration templates: Shared configuration templates or defaults become harder to maintain when they need to conditionally exclude fields.

Proposed Solution

Consider relaxing this validation to allow defaultNumPartitions to be set (but ignored) when topicType="non-partitioned". This would:

  • Make the API more user-friendly
  • Allow for more flexible configuration management
  • Maintain backward compatibility (non-partitioned topics would still be created correctly)
  • Simplify client code that doesn't need to conditionally set fields

Alternatively, if there's a technical reason this field must not be set, it would be helpful to document this clearly and potentially provide a clearer error message explaining why.

Question

Is this limitation necessary from a technical standpoint, or could it be relaxed to improve API usability?

Environment

  • Pulsar version: 3.x, 4.x
  • Component: Admin API / Namespace Policy

Activity

  1. Shawyeok commented on Nov 19, 2025

    @Shawyeok
    ContributorAuthor

    Note: This issue was organized and created with the assistance of AI to help identify and document API usability concerns.

  2. ChimdumebiNebolisa commented on Jan 19, 2026

    @ChimdumebiNebolisa
    Contributor

    Thanks for raising this.

    I’ve reviewed the code path and the limitation comes from AutoTopicCreationOverrideImpl.validateOverride, which explicitly rejects defaultNumPartitions when topicType=NON_PARTITIONED.

    My plan is to:

    • Relax the validation so defaultNumPartitions is allowed for non-partitioned topics.
    • Treat the value as ignored when topicType=NON_PARTITIONED, preserving current runtime behavior.
    • Update the existing unit test (testNumPartitionsOnNonPartitioned) to reflect the new valid state.
    • Add coverage to ensure no behavior change for non-partitioned topic creation.

    This improves API usability while keeping backward compatibility.

    I’ll open a PR shortly addressing this.

  3. ChimdumebiNebolisa commented on Jan 19, 2026

    @ChimdumebiNebolisa
    Contributor

    Update: I opened a PR to address this.

    • Relaxed validation to allow defaultNumPartitions to be set when topicType=non-partitioned (value is accepted/persisted).
    • Runtime behavior unchanged: the value is ignored for non-partitioned auto-creation.
    • Updated unit tests and added a broker test to verify non-partitioned topics remain non-partitioned.

    Fixes #24998 via PR: #25163

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions