-
Notifications
You must be signed in to change notification settings - Fork 840
Fixed View/Edit Data not handling generated columns properly. #9672 #9761
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Open
RohitBhati8269
wants to merge
1
commit into
pgadmin-org:master
Choose a base branch
from
RohitBhati8269:GH-9672
base: master
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
+118
−10
Open
Changes from all commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
40 changes: 40 additions & 0 deletions
40
...er/server_groups/servers/databases/schemas/tables/templates/columns/sql/12_plus/nodes.sql
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,40 @@ | ||
| SELECT DISTINCT att.attname as name, att.attnum as OID, pg_catalog.format_type(ty.oid,NULL) AS datatype, | ||
| pg_catalog.format_type(ty.oid,att.atttypmod) AS displaytypname, | ||
| att.attnotnull as not_null, | ||
| CASE WHEN att.atthasdef OR att.attidentity != '' OR ty.typdefault IS NOT NULL THEN True | ||
| ELSE False END as has_default_val, des.description, seq.seqtypid, | ||
| {# Detect generated columns to exclude from INSERT/UPDATE in View/Edit Data #} | ||
| CASE WHEN att.attgenerated = 's' THEN true ELSE false END as is_generated | ||
| FROM pg_catalog.pg_attribute att | ||
| JOIN pg_catalog.pg_type ty ON ty.oid=atttypid | ||
| JOIN pg_catalog.pg_namespace tn ON tn.oid=ty.typnamespace | ||
| JOIN pg_catalog.pg_class cl ON cl.oid=att.attrelid | ||
| JOIN pg_catalog.pg_namespace na ON na.oid=cl.relnamespace | ||
| LEFT OUTER JOIN pg_catalog.pg_type et ON et.oid=ty.typelem | ||
| LEFT OUTER JOIN pg_catalog.pg_attrdef def ON adrelid=att.attrelid AND adnum=att.attnum | ||
| LEFT OUTER JOIN (pg_catalog.pg_depend JOIN pg_catalog.pg_class cs ON classid='pg_class'::regclass AND objid=cs.oid AND cs.relkind='S') ON refobjid=att.attrelid AND refobjsubid=att.attnum | ||
| LEFT OUTER JOIN pg_catalog.pg_namespace ns ON ns.oid=cs.relnamespace | ||
| LEFT OUTER JOIN pg_catalog.pg_index pi ON pi.indrelid=att.attrelid AND indisprimary | ||
| LEFT OUTER JOIN pg_catalog.pg_description des ON (des.objoid=att.attrelid AND des.objsubid=att.attnum AND des.classoid='pg_class'::regclass) | ||
| LEFT OUTER JOIN pg_catalog.pg_sequence seq ON cs.oid=seq.seqrelid | ||
| WHERE | ||
|
|
||
| {% if tid %} | ||
| att.attrelid = {{ tid|qtLiteral(conn) }}::oid | ||
| {% endif %} | ||
| {% if table_name and table_nspname %} | ||
| cl.relname= {{table_name |qtLiteral(conn)}} and na.nspname={{table_nspname|qtLiteral(conn)}} | ||
| {% endif %} | ||
| {% if clid %} | ||
| AND att.attnum = {{ clid|qtLiteral(conn) }} | ||
| {% endif %} | ||
| {### To show system objects ###} | ||
| {% if not show_sys_objects and not has_oids %} | ||
| AND att.attnum > 0 | ||
| {% endif %} | ||
| {### To show oids in view data ###} | ||
| {% if has_oids %} | ||
| AND (att.attnum > 0 OR (att.attname = 'oid' AND att.attnum < 0)) | ||
| {% endif %} | ||
| AND att.attisdropped IS FALSE | ||
| ORDER BY att.attnum |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
🧩 Analysis chain
🏁 Script executed:
Repository: pgadmin-org/pgadmin4
Length of output: 6571
🏁 Script executed:
Repository: pgadmin-org/pgadmin4
Length of output: 4654
🏁 Script executed:
rg -n 'def has_oids' web/pgadmin/tools/sqleditorRepository: pgadmin-org/pgadmin4
Length of output: 216
🏁 Script executed:
rg -n 'res\[.rows.\]\[0\]' web/pgadmin/tools/sqleditor/utils -A 2 -B 2Repository: pgadmin-org/pgadmin4
Length of output: 1129
🏁 Script executed:
Repository: pgadmin-org/pgadmin4
Length of output: 1396
🏁 Script executed:
Repository: pgadmin-org/pgadmin4
Length of output: 1801
🏁 Script executed:
Repository: pgadmin-org/pgadmin4
Length of output: 781
🏁 Script executed:
Repository: pgadmin-org/pgadmin4
Length of output: 541
🏁 Script executed:
Repository: pgadmin-org/pgadmin4
Length of output: 1924
🏁 Script executed:
Repository: pgadmin-org/pgadmin4
Length of output: 886
🏁 Script executed:
Repository: pgadmin-org/pgadmin4
Length of output: 1985
🏁 Script executed:
Repository: pgadmin-org/pgadmin4
Length of output: 1656
🏁 Script executed:
rg -n 'test.*generated|test.*refetch|test.*update' web/pgadmin/tools/sqleditor/tests/ -lRepository: pgadmin-org/pgadmin4
Length of output: 46
🏁 Script executed:
Repository: pgadmin-org/pgadmin4
Length of output: 46
🏁 Script executed:
Repository: pgadmin-org/pgadmin4
Length of output: 882
🏁 Script executed:
Repository: pgadmin-org/pgadmin4
Length of output: 1049
🏁 Script executed:
Repository: pgadmin-org/pgadmin4
Length of output: 46
🏁 Script executed:
Repository: pgadmin-org/pgadmin4
Length of output: 1519
🏁 Script executed:
Repository: pgadmin-org/pgadmin4
Length of output: 817
🏁 Script executed:
Repository: pgadmin-org/pgadmin4
Length of output: 493
🏁 Script executed:
Repository: pgadmin-org/pgadmin4
Length of output: 3713
🏁 Script executed:
Repository: pgadmin-org/pgadmin4
Length of output: 46
🏁 Script executed:
# Trace the issue: confirm empty string pk_names is falsy in Jinja template cat web/pgadmin/tools/sqleditor/templates/sqleditor/sql/default/update.sqlRepository: pgadmin-org/pgadmin4
Length of output: 816
🏁 Script executed:
Repository: pgadmin-org/pgadmin4
Length of output: 2984
🏁 Script executed:
Repository: pgadmin-org/pgadmin4
Length of output: 46
🏁 Script executed:
Repository: pgadmin-org/pgadmin4
Length of output: 756
Guard refetch enqueueing when UPDATE cannot return identifiers.
When a table has generated columns, refetch is enabled (line 220). However, the UPDATE statement only includes a RETURNING clause if
pk_namesis non-empty ANDhas_oidsis false, OR ifhas_oidsis true (update.sql lines 9–10). If both conditions fail—e.g., a table with no primary keys on PostgreSQL 12+ (wherehas_oids()returns False)—the UPDATE has no RETURNING clause and returns an empty row set.Line 347 then unconditionally accesses
res['rows'][0]to extract parameters for the refetch SELECT, causing an IndexError when the list is empty. This crash can occur on valid tables with generated columns but no primary keys.Add a guard to enqueue refetch only when identifiers are returnable:
🤖 Prompt for AI Agents