GeezerVisonThe World Wide Web, restored to 800 pixels of glory. | ||||||||||||||||||||||||||||
| Home|About|Gaming cabinet|Archives|How it works|Starter sites | ||||||||||||||||||||||||||||
GeezerVison is showing github.com — fix: use pg_depend ownership instead of name guessing for SERIAL detection by kundansable · Pull Request #10167 · pgadmin-org/pgadmin4 Conversation
|
|
No actionable comments were generated in the recent review. 🎉 ℹ️ Recent review info⚙️ Run configurationConfiguration used: Path: .coderabbit.yaml Review profile: CHILL Plan: Pro Run ID: 📒 Files selected for processing (1)
🚧 Files skipped from review as they are similar to previous changes (1)
Walkthrough
ChangesSERIAL detection
Estimated code review effort: 2 (Simple) | ~10 minutes Sequence Diagram(s)sequenceDiagram
participant properties_sql
participant pg_depend
participant get_formatted_columns
properties_sql->>pg_depend: resolve default sequence dependency
pg_depend-->>properties_sql: return defseqrelid
properties_sql-->>get_formatted_columns: provide column metadata
get_formatted_columns->>get_formatted_columns: compare seqrelid and defseqrelid
get_formatted_columns-->>get_formatted_columns: reproject eligible columns as SERIAL
Possibly related issues
🚥 Pre-merge checks | ✅ 4 | ❌ 1❌ Failed checks (1 warning)
✅ Passed checks (4 passed)
✨ Finishing Touches🧪 Generate unit tests (beta)
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. Comment |
Sorry, something went wrong.
There was an error while loading. Please reload this page.
There was a problem hiding this comment.
The reason will be displayed to describe this comment to others. Learn more.
Actionable comments posted: 1
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.
Inline comments:
In
`@web/pgadmin/browser/server_groups/servers/databases/schemas/tables/columns/utils.py`:
- Around line 288-290: Update the serial-detection condition around
col.get('seqrelid') to require that the column default expression is also
recorded as depending on the same sequence OID (cs.oid) from properties.sql.
Ensure split ownership/default cases are excluded from serial conversion and
retain their original nextval default, and add a regression test covering a
column owned by one sequence whose default references another.
Fix all unresolved CodeRabbit comments on this PR:
Configuration used: Path: .coderabbit.yaml
Review profile: CHILL
Plan: Pro
Run ID: 3275255d-ffcc-438c-9356-dcab5eae5b1e
web/pgadmin/browser/server_groups/servers/databases/schemas/tables/columns/utils.py
Sorry, something went wrong.
There was an error while loading. Please reload this page.
There was an error while loading. Please reload this page.
Ownership and default are independent dependencies in PostgreSQL: a
column can own one sequence (pg_depend deptype='a', the existing
seqrelid check) while its DEFAULT's nextval() call names a completely
different one (pg_depend deptype='n' from the pg_attrdef entry). The
previous check only verified ownership, so a column in this split
ownership/default state was still wrongly reprojected as SERIAL,
discarding its real, distinct nextval() default.
Expose the default's own sequence dependency as defseqrelid in
properties.sql and require it to equal seqrelid before treating a
column as SERIAL, so split ownership/default columns keep their
original explicit nextval() default.
Add a mock-based regression test covering the split case, a genuine
SERIAL column, and identity columns, following the pattern already
used for shared-server unit tests since BaseTestGenerator's setUp()
needs a live server connection.
Verified against a real PostgreSQL 13 instance: a column owning
seq_owned but defaulting to nextval('seq_used') round-trips as
DEFAULT nextval('seq_used'::regclass), not SERIAL.
E127 continuation-line indent and E501 line-length (82 > 79) on the UTILS_MODULE string and the _make_column() defaults dict.
There was a problem hiding this comment.
The reason will be displayed to describe this comment to others. Learn more.
Actionable comments posted: 1
web/pgadmin/browser/server_groups/servers/databases/schemas/tables/columns/tests/test_serial_detection_unit.py (1)
47-54: 📐 Maintainability & Code Quality | 🔵 Trivial | ⚡ Quick winAnnotate
scenariosasClassVar.Ruff RUF012 flags this mutable class attribute. It is intentionally shared test metadata, so annotate it as
ClassVarrather than suppressing the warning.🤖 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/browser/server_groups/servers/databases/schemas/tables/columns/tests/test_serial_detection_unit.py` around lines 47 - 54, Annotate the shared mutable scenarios class attribute with ClassVar in the relevant test class, adding the necessary typing import if absent. Preserve the existing scenario metadata and avoid suppressing Ruff RUF012.Source: Linters/SAST tools
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.
Inline comments:
In
`@web/pgadmin/browser/server_groups/servers/databases/schemas/tables/templates/columns/sql/default/properties.sql`:
- Around line 40-47: Update the defseqdep join and defseqrelid derivation so
only sequence relations are considered and multiple dependency rows resolve
deterministically. Join defseqdep through pg_class with relkind = 'S', then add
the required stable tie-breaker or pre-collapse before comparing defseqrelid
with seqrelid; preserve the existing sequence dependency behavior.
---
Nitpick comments:
In
`@web/pgadmin/browser/server_groups/servers/databases/schemas/tables/columns/tests/test_serial_detection_unit.py`:
- Around line 47-54: Annotate the shared mutable scenarios class attribute with
ClassVar in the relevant test class, adding the necessary typing import if
absent. Preserve the existing scenario metadata and avoid suppressing Ruff
RUF012.
Fix all unresolved CodeRabbit comments on this PR:
Configuration used: Path: .coderabbit.yaml
Review profile: CHILL
Plan: Pro
Run ID: 1f48241f-1544-4b4e-b4c2-e1813acc51ab
web/pgadmin/browser/server_groups/servers/databases/schemas/tables/columns/tests/test_serial_detection_unit.pyweb/pgadmin/browser/server_groups/servers/databases/schemas/tables/columns/utils.pyweb/pgadmin/browser/server_groups/servers/databases/schemas/tables/templates/columns/sql/default/properties.sql
Sorry, something went wrong.
There was an error while loading. Please reload this page.
There was an error while loading. Please reload this page.
The defseqdep join filtered the default's own pg_depend row down to classid='pg_attrdef' and deptype='n', but never checked that the referenced object (refobjid) is actually a sequence. A default expression can carry other deptype='n' dependencies on non-sequence pg_class objects too - e.g. a composite type referenced via a cast inside the expression - which would fan the LEFT JOIN out to multiple rows for the same column and let SELECT DISTINCT ON (att.attnum) pick an arbitrary one, occasionally resolving defseqrelid to something other than the intended sequence. Verified against a real server: a default expression referencing both a sequence and a composite type produces two deptype='n' pg_depend rows, one per object. Join through pg_class with relkind='S' so only sequence dependencies are considered, and collapse the lookup into a scalar subquery (the same pattern already used for typnspname/isdup elsewhere in this template) with an ORDER BY ... LIMIT 1 tie-breaker, so it can never fan out the outer query regardless of how many dependencies exist. Existing single-dependency behavior (the common case) is unchanged.
There was an error while loading. Please reload this page.
There was an error while loading. Please reload this page.
Successfully merging this pull request may close these issues.
Issue with CREATE script: Schema Diff generates wrong SQL for SERIAL columns after renaming, or when a sequence name accidentally matches
There was an error while loading. Please reload this page.