Skip to content

fix: preserve alert receiver fields during partial updates (#6711) - #7038

Open
juicewcode wants to merge 3 commits into
apache:masterfrom
juicewcode:fix/6711-alert-receiver-partial-update-
Open

juicewcode wants to merge 3 commits into
apache:masterfrom
juicewcode:fix/6711-alert-receiver-partial-update-

Conversation

@juicewcode

@juicewcode juicewcode commented Sep 7, 2026

Copy link
Copy Markdown
Contributor

Fixes #6711

Summary

  • Replace updateByPrimaryKey with updateByPrimaryKeySelective for alert receiver updates.
  • Add the selective mapper method and dynamic MyBatis SQL.
  • Convert enable and matchAll from primitive boolean to nullable Boolean.
  • Omitted nullable fields are no longer written back to the database.
  • Preserve the default value true when creating a new alert receiver.
  • Add null-safe checks in alert dispatch logic.

Test

  • Updated AlertReceiverServiceTest to verify selective updates and prevent calls to the full-column update method.
  • Updated AlertTransferTest for nullable Boolean mapping.
  • Added coverage for null enable and matchAll values.
  • Existing alert dispatch test paths continue to set explicit Boolean values.
  • Performed static checks for remaining primitive getter usage, XML validity, and whitespace errors.

Make sure that:

  • You have read the contribution guidelines.
  • You submit test cases (unit or integration tests) that back your changes.
  • Your local test passed ./mvnw clean install -Dmaven.javadoc.skip=true.

)

  Use selective updates for alert receivers and convert enable and matchAll to nullable Boolean values.
  Preserve database values when these fields are omitted, keep true as the default for new receivers, and add null-safe
  alert dispatch handling.

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

🟡 Changes recommended

The new selective MyBatis update binds accessToken as jdbcType=TINYINT despite being a String/VARCHAR, which can cause incorrect updates or runtime SQL type conversion errors.

Get a fresh assessment by requesting another Copilot review.

Pull request overview

This PR addresses #6711 by preventing partial alert receiver updates from overwriting omitted columns with NULL, switching the admin update path to a selective MyBatis update and making enable/matchAll nullable so “not provided” can be preserved.

Changes:

  • Use updateByPrimaryKeySelective for alert receiver updates and add the corresponding mapper method + dynamic SQL.
  • Convert enable and matchAll from primitive boolean to nullable Boolean, and update mapping/tests accordingly.
  • Make alert dispatch filtering null-safe (Boolean.TRUE.equals(...)) and preserve true defaults on create in the service layer.
File summaries
File Description
shenyu-alert/src/main/java/org/apache/shenyu/alert/model/AlertReceiverDTO.java Make enable/matchAll nullable to support selective updates without implicit false/default writes.
shenyu-admin/src/test/java/org/apache/shenyu/admin/transfer/AlertTransferTest.java Update mapping assertions for nullable Booleans and add null-mapping coverage.
shenyu-admin/src/test/java/org/apache/shenyu/admin/service/AlertReceiverServiceTest.java Verify selective update usage and ensure full-column update isn’t called.
shenyu-admin/src/main/resources/mappers/alert-receiver-sqlmap.xml Add updateByPrimaryKeySelective dynamic SQL for partial updates.
shenyu-admin/src/main/java/org/apache/shenyu/admin/transfer/AlertTransfer.java Update DTO/DO mapping for nullable enable/matchAll.
shenyu-admin/src/main/java/org/apache/shenyu/admin/service/impl/AlertReceiverServiceImpl.java Default enable/matchAll to true on create and switch update to selective update.
shenyu-admin/src/main/java/org/apache/shenyu/admin/service/impl/AlertDispatchServiceImpl.java Make dispatch filtering null-safe for nullable Booleans.
shenyu-admin/src/main/java/org/apache/shenyu/admin/model/entity/AlertReceiverDO.java Make persisted enable/matchAll nullable to preserve omitted fields.
shenyu-admin/src/main/java/org/apache/shenyu/admin/mapper/AlertReceiverMapper.java Add updateByPrimaryKeySelective to the mapper interface.
Review details
  • Files reviewed: 9/9 changed files
  • Comments generated: 1
  • Review effort level: Lite

💡 Add a code-review agent skill or configure MCP servers for context-aware, tailored reviews. Learn more in the docs.

<if test="email != null">email = #{email,jdbcType=VARCHAR},</if>
<if test="hookUrl != null">hook_url = #{hookUrl,jdbcType=VARCHAR},</if>
<if test="wechatId != null">wechat_id = #{wechatId,jdbcType=VARCHAR},</if>
<if test="accessToken != null">access_token = #{accessToken,jdbcType=TINYINT},</if>

@Aias00 Aias00 left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Approved as PMC (Aias00). Coherent, well-scoped fix with regression tests; green CI, mergeable. Reviewed the diff.

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.

[BUG] AlertReceiverServiceImpl.updateReceiver uses full updateByPrimaryKey, nulling omitted columns

3 participants