Skip to content

fix(topic): allow a blank update to clear the persisted topic remark - #4275

Merged
lizhimins merged 1 commit into
apache:rocketmq-studiofrom
btlqql:codex/btl-topic-remark-clear
Sep 15, 2026
Merged

lizhimins merged 1 commit into
apache:rocketmq-studiofrom
btlqql:codex/btl-topic-remark-clear

Conversation

@btlqql

@btlqql btlqql commented Sep 13, 2026

Copy link
Copy Markdown
Contributor

What is the purpose of the change

POST /api/topics/update could not remove a topic's stored remark. RocketMQAdminClientImpl.updateTopic only wrote the cached row when the submitted value had text:

if (StringUtils.hasText(topic.getRemark())) {
    existing.setRemark(topic.getRemark());
}

so a blank submission behaved exactly like an omitted one. TopicVO.remark / UpdateTopicDTO.remark are plain nullable strings with no validation and there is no separate clear flag (unlike clearApiKey / clearDingtalkSigningSecret in general settings), so a blank remark is the only way a caller can say "this topic has no remark" — and that value was discarded. The rmq_instance_topic row kept the previous remark while the endpoint answered 200, so the topic list showed the old text again on the next load.

Clearing is a two-part change. updateById omits null entity fields (FieldStrategy.NOT_NULL, no update-strategy override in application.yml), which is the mechanism already handled for the ACL user/rule columns in #3342, so the cleared remark is assigned explicitly instead of relying on the entity write. An omitted remark still keeps the stored value, which is the partial-update behaviour the existing comment in this method describes.

The response now reports the persisted remark rather than the submitted one, so a clear and an omitted value cannot be reported as a state the database does not hold.

Brief changelog

  • RocketMQAdminClientImpl.updateTopic: treat a submitted blank remark as a clear (keep the stored value only when the remark is null), and assign remark explicitly through an UpdateWrapper when it is cleared, because updateById skips null entity fields.
  • Echo the persisted remark back on the returned TopicVO.
  • RocketMQAdminClientImplTest: two new cases — a blank remark clears the column and returns an empty remark; an omitted remark keeps the stored value and issues no extra assignment.

Verification

Red first, on the unmodified implementation with only the new tests added:

mvn -f server/pom.xml -B -DskipITs -Dtest=RocketMQAdminClientImplTest -DfailIfNoTests=false test
[ERROR] Tests run: 48, Failures: 2, Errors: 0, Skipped: 0, Time elapsed: 2.480 s <<< FAILURE! -- in org.apache.rocketmq.studio.provider.apache.RocketMQAdminClientImplTest
[ERROR]   RocketMQAdminClientImplTest.updateTopicClearsTheStoredRemarkWhenTheRequestSubmitsABlankRemark:638
[ERROR]   RocketMQAdminClientImplTest.updateTopicKeepsTheStoredRemarkWhenTheRequestOmitsIt:664
[INFO] BUILD FAILURE

...:638 is verify(topicMapper).update(isNull(), captor.capture()) (no assignment was issued, so the column was never cleared); ...:664 is the returned topic still carrying the submitted null instead of the persisted remark.

Green after the change:

mvn -f server/pom.xml -B -DskipITs -Dtest=RocketMQAdminClientImplTest -DfailIfNoTests=false test
[INFO] Tests run: 48, Failures: 0, Errors: 0, Skipped: 0, Time elapsed: 2.455 s -- in org.apache.rocketmq.studio.provider.apache.RocketMQAdminClientImplTest
[INFO] BUILD SUCCESS

Whole backend suite on this branch (mvn -f server/pom.xml -B -DskipITs test): Tests run: 2153, Failures: 5, Errors: 5, Skipped: 0. I also ran the same command on the unmodified base commit 6c24d2ed: Tests run: 2151, Failures: 5, Errors: 5 with the identical 10 failing test ids — 8 need a POSIX sh CLI that this Windows machine does not have (CliAgentProviderTest, ClaudeCodeAgentProviderTest) and 2 are AuthCorsIntegrationTest.shouldRejectNonAdminMutationBeforeControllerExecution / shouldStillRejectAnonymousProtectedRequests, which also fail on the base and are aligned separately in #4217. No other test moved.

The DB path itself was not exercised end to end here (no MySQL in this environment); the regression test asserts the assignment that the fix issues, in the same style as the accepted ACL fix in #3342.

Fixes #4272

@RockteMQ-AI RockteMQ-AI left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Summary

Fix for topic remark not being cleared when a blank value is submitted. This PR also introduces an important semantic distinction: null remark = omitted (keep stored value), blank remark = explicitly cleared.

Review

Correctness ✅

  • The clearRemark flag correctly distinguishes between omitted (null) and explicitly cleared (blank) remarks.
  • When clearRemark is true, the entity field is set to null (skipped by updateById), then an explicit UpdateWrapper SET NULL follows — same pattern as #3342, #4276, #4277.
  • The response fix (topic.setRemark(existing.getRemark())) ensures the returned VO reflects the persisted state, preventing the UI from displaying stale data.

Tests ✅

  • Two new tests cover both the clear path (blank remark → null in DB) and the no-op path (omitted remark → stored value retained).
  • ArgumentCaptor assertions verify the exact SQL and parameter values.

Code quality ✅

  • Clear inline comments explaining the null-vs-blank semantics and the MyBatis-Plus workaround.
  • The response fix is a thoughtful addition that prevents UI confusion.

LGTM.

`RocketMQAdminClientImpl.updateTopic` only wrote the cached row's remark when the submitted value
had text:

    if (StringUtils.hasText(topic.getRemark())) {
        existing.setRemark(topic.getRemark());
    }

so a blank submission behaved exactly like an omitted one. `TopicVO.remark` / `UpdateTopicDTO.remark`
are plain nullable strings with no validation and there is no separate clear flag (unlike
`clearApiKey` / `clearDingtalkSigningSecret` in general settings), so a blank remark is the only way
a caller can say "this topic has no remark" - and that value was discarded. The `rmq_instance_topic`
row therefore keeps the previous remark while the endpoint answers 200, and the topic list shows the
old text again on the next load.

Clearing the column is a two-part change. `updateById` omits null entity fields
(`FieldStrategy.NOT_NULL`), the same mechanism already handled for the ACL user/rule columns in
apache#3342, so the cleared remark is assigned explicitly instead of relying on the entity write. An
omitted remark still keeps the stored value, which is the partial-update behaviour the existing
comment in this method describes.

The response now reports the persisted remark instead of the submitted one, so a clear and an
omitted value cannot be reported as a state the database does not hold.

`RocketMQAdminClientImplTest` pins both directions: a blank remark clears the column through an
explicit assignment (and the returned topic is empty), while an omitted remark keeps the stored value
and issues no assignment at all.

Fixes apache#4272

Signed-off-by: btlqql <2977859784@qq.com>
(cherry picked from commit 925958f)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants