Skip to content
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

Composite primary key panic: Too many rows found. #274

Closed
oiime opened this issue Jan 18, 2021 · 4 comments
Closed

Composite primary key panic: Too many rows found. #274

oiime opened this issue Jan 18, 2021 · 4 comments
Labels
Milestone

Comments

@oiime
Copy link

oiime commented Jan 18, 2021

Describe the bug

Panic while running init on a table with a composite primary (3 column)

reform-db: 2021/01/18 13:36:59.455251 cmd_init.go:117: ColumnName: `scope_value` (string), OrdinalPosition: 3 (int)
reform-db: 2021/01/18 13:36:59.455258 cmd_init.go:117: ColumnName: `scope` (string), OrdinalPosition: 2 (int)
reform-db: 2021/01/18 13:36:59.455269 cmd_init.go:117: ColumnName: `key` (string), OrdinalPosition: 1 (int)
reform-db: 2021/01/18 13:36:59.455275 cmd_init.go:135: Too many rows found. Please report this bug.
panic: Too many rows found. Please report this bug.

goroutine 1 [running]:
gopkg.in/reform.v1/internal.(*Logger).Fatalf(0xc000400340, 0xad8583, 0x2c, 0x0, 0x0, 0x0)
	/home/ism/go/src/gopkg.in/reform.v1/internal/logger.go:51 +0xea
main.getPrimaryKeyColumn(0xc000414b00, 0xc0004069fa, 0x6, 0xc000406a00, 0x6, 0xc000406a06, 0x6, 0x0)
	/home/ism/go/src/gopkg.in/reform.v1/reform-db/cmd_init.go:135 +0xb16
main.initModelsInformationSchema(0xc000414b00, 0xad3f0c, 0x25, 0xae7178, 0x0, 0xc000061660, 0x1233400)
	/home/ism/go/src/gopkg.in/reform.v1/reform-db/cmd_init.go:157 +0x2ad
main.cmdInit(0xc000414b00, 0xc00002c034, 0x22)
	/home/ism/go/src/gopkg.in/reform.v1/reform-db/cmd_init.go:202 +0xc4d
main.main()
	/home/ism/go/src/gopkg.in/reform.v1/reform-db/main.go:146 +0x500

To Reproduce
Create a table with more than one column in the primary key

Expected behavior

for reform to either deal with composite primary keys or quietly skip it for that table, currently cmd_init.go seems to panic if the number of columns involved is larger than 1 but also has a warning if it is equal to 1 if OrdinalPosition is bigger than 1 which I do not think is a case that can happen

@AlekSi
Copy link
Member

AlekSi commented Jan 18, 2021

What database is that? And please provide a CREATE TABLE statement

@oiime
Copy link
Author

oiime commented Jan 18, 2021

Postgres 12.5

I assume it'll happen irregardless of table structur so long that the PRIMARY KEY constraint is on more than one column

CREATE TABLE public.config (
    revision integer DEFAULT 0,
    cga uuid,
    key text NOT NULL,
    scope public.config_scopes NOT NULL,
    scope_value text NOT NULL,
    value jsonb DEFAULT 'null'::jsonb NOT NULL,
    created_at timestamp with time zone DEFAULT CURRENT_TIMESTAMP NOT NULL,
    updated_at timestamp with time zone DEFAULT CURRENT_TIMESTAMP NOT NULL
);

ALTER TABLE ONLY public.config ADD CONSTRAINT config_pkey PRIMARY KEY (key, scope, scope_value);

@AlekSi
Copy link
Member

AlekSi commented Jan 18, 2021

Thanks, I will take a look

@AlekSi AlekSi added the bug label Jan 18, 2021
@AlekSi AlekSi modified the milestones: v1.5.0, v1.5.1 Jan 18, 2021
AlekSi added a commit that referenced this issue Aug 27, 2021
AlekSi added a commit that referenced this issue Aug 27, 2021
@AlekSi
Copy link
Member

AlekSi commented Aug 27, 2021

v1.5.1 is released with a fix for this issue.

@AlekSi AlekSi closed this as completed Aug 27, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants