Copilot commented on code in PR #1141:
URL: 
https://github.com/apache/incubator-seata-go/pull/1141#discussion_r3836374125


##########
pkg/datasource/sql/exec/at/update_executor.go:
##########
@@ -360,3 +369,20 @@ func (u *updateExecutor) buildBeforeImageSQL(ctx 
context.Context, args []driver.
 
        return sql, u.buildSelectArgs(&selStmt, args), nil
 }
+
+func (u *updateExecutor) validatePrimaryKeyAssignments(metaData 
*types.TableMeta) error {
+       for _, assignment := range u.parserCtx.UpdateStmt.List {
+               for _, primaryKey := range metaData.GetPrimaryKeyOnlyName() {
+                       if !strings.EqualFold(assignment.Column.Name.O, 
primaryKey) {
+                               continue
+                       }
+
+                       columnExpr, selfAssignment := 
assignment.Expr.(*ast.ColumnNameExpr)
+                       if selfAssignment && 
strings.EqualFold(columnExpr.Name.Name.O, primaryKey) {
+                               continue
+                       }
+                       return fmt.Errorf("updating primary key column %q is 
not supported", assignment.Column.Name.O)
+               }
+       }
+       return nil
+}

Review Comment:
   validatePrimaryKeyAssignments uses an unchecked type assertion 
(`assignment.Expr.(*ast.ColumnNameExpr)`), which will panic for common UPDATE 
forms like `SET id = ?` or `SET id = id + 1`. This should be a safe type 
assertion and treat non-self-assignments as unsupported PK updates.



-- 
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]


---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]

Reply via email to