Postgres function inspector reads wrong column ordinals: any schema with a function fails integrity inspection

Aperta Adatta ai principianti
#137 3 commenti 0 reazioni 0 assegnatari Vedi su GitHub

I maintainer di solito rispondono entro 1 giorno

Nessuno ha ancora preso questa issue.

Valutazione

Difficoltà
1/5
Tempo stimato
1-3 ore
Idoneità per principianti
92/100
Tipo di issue
Bug
Chiarezza
Specificata chiaramente
Stato di attività
Attiva
Stack tecnologico
csharp, postgresql, sql
Ambito
database

Direzione di ricerca

Iniziate dalla query del catalogo functions e dal reader in Migration/Nimblesite.DataProvider.Migration.Postgres/PostgresSupportSchemaInspector.cs, confrontando le colonne selezionate con gli ordinali usati da GetString, IsDBNull e GetBoolean. Eseguite DataProviderMigrate migrate --provider postgres sullo schema fornito contenente functions: per riprodurre l’errore di integrità. Il lavoro è completo quando la funzione viene ispezionata con il proprietario, il percorso di ricerca e i flag di revoca corretti, la migrazione supera la verifica di integrità e la sua riesecuzione non produce modifiche.

Scritto dal modello di indicizzazione a partire dal testo della issue.

Descrizione

Bug

At refactor/deslop-ten-percent (3b4e356522affc61b466d8e87ef5232319c9d7a0), DataProviderMigrate migrate --provider postgres fails for every schema that has a function in the inspected schema (for example a top-level functions: entry):

Error: schema integrity inspection failed: Reading as 'System.String' is not supported for fields having DataTypeName 'boolean'
Error: migration apply failed: Schema integrity verification failed before commit

Cause

Migration/Nimblesite.DataProvider.Migration.Postgres/PostgresSupportSchemaInspector.cs: the functions catalog query selects, in order,

ordinal column
7 p.prosecdef
8 p.prosrc
9 owner.rolname AS owner_role
10 search_path_config
11 revoke_public_execute (boolean)
12 execute_roles

but the reader uses

OwnerRole = reader.GetString(10),
SearchPath = ParseSearchPathConfig(reader.IsDBNull(11) ? null : reader.GetString(11)),
RevokePublicExecute = reader.GetBoolean(9),

so it reads a boolean as a string (and the owner as a boolean).

Fix

OwnerRole = reader.GetString(9),
SearchPath = ParseSearchPathConfig(reader.IsDBNull(10) ? null : reader.GetString(10)),
RevokePublicExecute = reader.GetBoolean(11),

Verified on PostgreSQL with a securityDefiner function declaring ownerRole, searchPath, executeRoles and revokePublicExecute: with the three ordinals corrected, migrate applies, passes the integrity check and replays as a no-op.

Repro

roles:
  - { name: demo_writer, login: false }
functions:
  - schema: demo
    name: touch
    returns: void
    language: sql
    volatility: volatile
    securityDefiner: true
    ownerRole: demo_writer
    searchPath: [pg_catalog]
    body: SELECT 1

Related gaps found at the same time

  • Grants have no column lists (GRANT SELECT (a, b) ON TABLE …); only table-level privileges can be declared, inspected and verified.
  • Roles have no way to receive a password (for example from an environment variable).
  • A schema cannot be created by the migration (CREATE SCHEMA must be run by hand first).
Lingua principale
C#
Stelle
68
Fork
4
Merge medio
50m
PR unite (30g)
2

Preparare l'ambiente

Apri in Codespaces

Avvia il container di sviluppo del progetto nel browser, con il tuo account GitHub.

Come iniziare

  1. Leggi tutta la issue e poi la guida ai contributi del progetto.
  2. Commenta sulla issue per dire che te ne occupi tu — evita che due persone facciano lo stesso lavoro.
  3. Fai un fork del repository e lavora su un branch.
  4. Apri una pull request che faccia riferimento al numero della issue.

Altre issue di Nimblesite/DataProvider

Tutte le issue di Nimblesite/DataProvider

Issue simili

Altre issue su C#

Ricevi le nuove issue nella tua casella

Un breve riepilogo di issue GitHub adatte ai principianti.