Skip to content

fix: exclude non-editable/alias columns from Query Tool row UPDATE#10171

Open
kundansable wants to merge 1 commit into
pgadmin-org:masterfrom
kundansable:fix-10103-alias-column-update
Open

fix: exclude non-editable/alias columns from Query Tool row UPDATE#10171
kundansable wants to merge 1 commit into
pgadmin-org:masterfrom
kundansable:fix-10103-alias-column-update

Conversation

@kundansable

@kundansable kundansable commented Jul 22, 2026

Copy link
Copy Markdown
Contributor

Summary

Fixes #10103 — editing a row in the Query Tool result grid fails to save with column "..." does not exist when the query includes an aliased/computed column (e.g. first_name || ' ' || last_name AS the_name), even though that column is already shown as read-only (lock icon) in the grid.

Root Cause

save_changed_data() has two code paths — added (INSERT) and updated (UPDATE). The added path already filters the outgoing payload down to real, editable table columns (fixed for #9939 in #10015), using the same columns_info[...]['is_editable'] metadata that drives the grid's lock icon. The updated path never got the equivalent filter, so an edited row that includes an alias/expression column sends that alias straight into the generated UPDATE ... SET clause — and Postgres rejects it because there's no such real column.

Fix

Apply the same editable-columns guard to the updated branch: drop any key from the changed-row payload that isn't a real, editable table column, and skip the row entirely if nothing editable remains after filtering (avoiding an empty/invalid SET clause).

Test Steps

  1. In the Query Tool, run:
    DROP TABLE IF EXISTS some_table;
    CREATE TABLE some_table (id INT PRIMARY KEY, first_name TEXT, last_name TEXT);
    INSERT INTO some_table VALUES (1, 'John', 'Doe');
    
    SELECT id, first_name, last_name,
           first_name || ' ' || last_name AS the_name
    FROM some_table;
  2. In the result grid, edit first_name from John to Jane on the existing row.
  3. Press F5 / Save.
  4. Expected: save succeeds; only first_name is updated. No column "the_name" ... does not exist error.
  5. Regression: repeat on a query with no alias/expression columns and confirm normal edits still save correctly.

Summary by CodeRabbit

  • Bug Fixes
    • Improved saving of edited table data when query results include calculated, aliased, or otherwise non-editable columns.
    • Prevented invalid update operations when a row contains no editable fields.
    • Changes to editable table values are now applied more reliably without errors caused by non-table result columns.

The added (INSERT) branch of save_changed_data() already filtered out
columns that aren't backed by a real table column (added for pgadmin-org#9939 /
pgadmin-org#10015), but the updated (UPDATE) branch did not. Editing a row that
includes an aliased/expression column (e.g.
first_name || ' ' || last_name AS the_name) sent that alias into the
generated UPDATE's SET clause, which fails with "column ... does not
exist" even though the grid already marks the column read-only.

Apply the same editable-columns guard to the updated branch, and skip
the row entirely if nothing editable remains after filtering.

Fixes pgadmin-org#10103
@coderabbitai

coderabbitai Bot commented Jul 22, 2026

Copy link
Copy Markdown

Review Change Stack

Walkthrough

The updated save path filters row data to editable table columns before generating UPDATE statements and skips rows containing no editable fields.

Changes

Update filtering

Layer / File(s) Summary
Filter editable update fields
web/pgadmin/tools/sqleditor/utils/save_changed_data.py
The updated operation removes expression and alias columns from row data and skips rows when no editable fields remain.

Estimated code review effort: 2 (Simple) | ~10 minutes

🚥 Pre-merge checks | ✅ 5
✅ Passed checks (5 passed)
Check name Status Explanation
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title check ✅ Passed The title clearly summarizes the main change: filtering non-editable or aliased columns out of Query Tool row updates.
Docstring Coverage ✅ Passed No functions found in the changed files to evaluate docstring coverage. Skipping docstring coverage check.
Linked Issues check ✅ Passed Check skipped because no linked issues were found for this pull request.
Out of Scope Changes check ✅ Passed Check skipped because no linked issues were found for this pull request.
✨ Finishing Touches
🧪 Generate unit tests (beta)
  • Create PR with unit tests

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share

Comment @coderabbitai help to get the list of available commands.

@coderabbitai coderabbitai Bot 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.

🧹 Nitpick comments (1)
web/pgadmin/tools/sqleditor/utils/save_changed_data.py (1)

180-194: 📐 Maintainability & Code Quality | 🔵 Trivial | ⚡ Quick win

Add regression coverage for updated rows with read-only aliases.

Please add or verify tests covering:

  • an updated row containing both an editable column and an alias/computed column;
  • a row containing only a non-editable alias.

Assert that the editable value is persisted and the alias-only row produces no UPDATE.

🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

In `@web/pgadmin/tools/sqleditor/utils/save_changed_data.py` around lines 180 -
194, Extend the regression tests covering the save-changed-data flow around the
data filtering logic to include a row with both an editable column and a
non-editable alias, asserting the editable value is persisted, and a row
containing only the alias, asserting no UPDATE is generated or executed. Reuse
the existing test fixtures and assertions for updated rows and SQL persistence.
🤖 Prompt for all review comments with AI agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

Nitpick comments:
In `@web/pgadmin/tools/sqleditor/utils/save_changed_data.py`:
- Around line 180-194: Extend the regression tests covering the
save-changed-data flow around the data filtering logic to include a row with
both an editable column and a non-editable alias, asserting the editable value
is persisted, and a row containing only the alias, asserting no UPDATE is
generated or executed. Reuse the existing test fixtures and assertions for
updated rows and SQL persistence.

ℹ️ Review info
⚙️ Run configuration

Configuration used: Path: .coderabbit.yaml

Review profile: CHILL

Plan: Pro

Run ID: d701b2fa-7918-4e34-9c15-30690aac3d3f

📥 Commits

Reviewing files that changed from the base of the PR and between b15c745 and 8e95bb4.

📒 Files selected for processing (1)
  • web/pgadmin/tools/sqleditor/utils/save_changed_data.py

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.

Editing a row with expression/alias columns in Query Tool fails to save with "column does not exist" error

1 participant