Skip to content

Preserve nested table qualifiers in MySQL upsert policy filters #2911

Open

Description

@coderabbitai

Summary

MySQL upserts using ON DUPLICATE KEY UPDATE can strip table qualifiers from nested computed-field expressions in update policy filters. When a nested query uses the mutation model name as a table name or alias, stripping that qualifier can make column references ambiguous, for example when the nested query joins another table with the same column name.

The reported case involves an update policy using a computed field whose implementation queries its own model table without an alias. This case was not tested in the original pull request.

Required changes

  • Make TableReferenceStripper in packages/plugins/policy/src/policy-handler.ts aware of query scope when it processes duplicate-key update policy filters.
  • Preserve references to tables and aliases declared in nested queries, including names that match the mutation model.
  • Handle correlated references to the outer mutation model correctly. Review the computed-field policy expression path in packages/plugins/policy/src/expression-transformer.ts.

Acceptance criteria

  • Add a MySQL regression test for an upsert with an update policy using a computed field whose nested query joins tables with a shared column name and references the mutation model name.
  • Verify that nested table qualifiers remain intact and the upsert evaluates the policy without an ambiguous-column error.
  • Add coverage for correlated outer references and ordinary duplicate-key update policy filters, including allowed and denied updates.

Context

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

Metadata

Metadata

Assignees

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