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

sqlc panics on v1.21.0 in sqlite.getTables #2729

Closed
jamietanna opened this issue Sep 14, 2023 · 5 comments · Fixed by #2732
Closed

sqlc panics on v1.21.0 in sqlite.getTables #2729

jamietanna opened this issue Sep 14, 2023 · 5 comments · Fixed by #2732

Comments

@jamietanna
Copy link

jamietanna commented Sep 14, 2023

Version

1.21.0

What happened?

Panic received when trying to generate code

Relevant log output

panic: runtime error: invalid memory address or nil pointer dereference
[signal SIGSEGV: segmentation violation code=0x1 addr=0x100 pc=0xf27ae8]

goroutine 6 [running]:
github.com/sqlc-dev/sqlc/internal/engine/sqlite.(*cc).getTables(0x492201?, 0xc000989980)
        /home/jamie/go/pkg/mod/github.com/sqlc-dev/sqlc@v1.21.0/internal/engine/sqlite/convert.go:556 +0x568
github.com/sqlc-dev/sqlc/internal/engine/sqlite.(*cc).convertMultiSelect_stmtContext(0x4931ec?, 0xc000989968)
        /home/jamie/go/pkg/mod/github.com/sqlc-dev/sqlc@v1.21.0/internal/engine/sqlite/convert.go:404 +0x537
github.com/sqlc-dev/sqlc/internal/engine/sqlite.(*cc).convert(0x0?, {0x2842340?, 0xc000989968?})
        /home/jamie/go/pkg/mod/github.com/sqlc-dev/sqlc@v1.21.0/internal/engine/sqlite/convert.go:1159 +0x2df
github.com/sqlc-dev/sqlc/internal/engine/sqlite.(*cc).convertSql_stmtContext(0x4931ec?, 0xc000989950)
        /home/jamie/go/pkg/mod/github.com/sqlc-dev/sqlc@v1.21.0/internal/engine/sqlite/convert.go:718 +0x1988
github.com/sqlc-dev/sqlc/internal/engine/sqlite.(*cc).convert(0xc000c95d50?, {0x2842360?, 0xc000989950?})
        /home/jamie/go/pkg/mod/github.com/sqlc-dev/sqlc@v1.21.0/internal/engine/sqlite/convert.go:1162 +0x2f9
github.com/sqlc-dev/sqlc/internal/engine/sqlite.(*Parser).Parse(0xc00005ea10?, {0x283d180?, 0xc0005c4b60?})
        /home/jamie/go/pkg/mod/github.com/sqlc-dev/sqlc@v1.21.0/internal/engine/sqlite/parse.go:71 +0x54f
github.com/sqlc-dev/sqlc/internal/compiler.(*Compiler).parseQueries(0xc00029dc00, {{0x0, 0x0, {0x0, 0x0}, 0x0, 0x0, 0x0}})
        /home/jamie/go/pkg/mod/github.com/sqlc-dev/sqlc@v1.21.0/internal/compiler/compile.go:74 +0x25a
github.com/sqlc-dev/sqlc/internal/compiler.(*Compiler).ParseQueries(...)
        /home/jamie/go/pkg/mod/github.com/sqlc-dev/sqlc@v1.21.0/internal/compiler/engine.go:49
github.com/sqlc-dev/sqlc/internal/cmd.parse({_, _}, {_, _}, {_, _}, {{0xc000321cfa, 0x6}, {0xc0004381a0, 0x1, ...}, ...}, ...)
        /home/jamie/go/pkg/mod/github.com/sqlc-dev/sqlc@v1.21.0/internal/cmd/generate.go:350 +0x293
github.com/sqlc-dev/sqlc/internal/cmd.Generate.func1()
        /home/jamie/go/pkg/mod/github.com/sqlc-dev/sqlc@v1.21.0/internal/cmd/generate.go:224 +0x7d7
golang.org/x/sync/errgroup.(*Group).Go.func1()
        /home/jamie/go/pkg/mod/golang.org/x/sync@v0.3.0/errgroup/errgroup.go:75 +0x56
created by golang.org/x/sync/errgroup.(*Group).Go in goroutine 1
        /home/jamie/go/pkg/mod/golang.org/x/sync@v0.3.0/errgroup/errgroup.go:72 +0x96
exit status 2
generate.go:3: running "go": exit status 1

Database schema

CREATE TABLE IF NOT EXISTS aws_elasticache_datastores (
  account_id TEXT NOT NULL,
  region TEXT NOT NULL,
  arn TEXT NOT NULL,
  name TEXT NOT NULL,
  engine TEXT NOT NULL,
  engine_version TEXT NOT NULL,

  -- tags is a JSON object
  tags TEXT NOT NULL,

  UNIQUE (account_id, region, arn) ON CONFLICT REPLACE
);

CREATE TABLE IF NOT EXISTS aws_elasticache_datastore_engines (
  engine TEXT NOT NULL,
  engine_version TEXT NOT NULL,
  deprecation TEXT NOT NULL,

  UNIQUE (engine, engine_version) ON CONFLICT REPLACE
);

SQL queries

-- name: RetrieveAllWithDeprecation :many
select
  arn,
  name,
  d.engine,
  d.engine_version,
  e.deprecation
from
  aws_elasticache_datastores d
inner join aws_elasticache_datastore_engines e
where d.engine = e.engine
and d.engine_version like e.engine_version || '.%'

Configuration

No response

Playground URL

https://play.sqlc.dev/p/e3437505ebfba3f93003f631460d29cedd52b246eabbcb030281e3172eb36097

What operating system are you using?

No response

What database engines are you using?

SQLite

What type of code are you generating?

Go

@jamietanna jamietanna added bug Something isn't working triage New issues that hasn't been reviewed labels Sep 14, 2023
@jamietanna jamietanna changed the title sqlc panics on v1.21.0 sqlc panics on v1.21.0 with inner join Sep 14, 2023
@jamietanna
Copy link
Author

Tracked down which query was the problem and have updated ☝️

@jamietanna jamietanna changed the title sqlc panics on v1.21.0 with inner join sqlc panics on v1.21.0 in sqlite.getTables Sep 14, 2023
@jamietanna
Copy link
Author

In my code, I'm seeing this line panic because jc from this line is nil.

@jamietanna
Copy link
Author

I've raised #2730 for this, but not sure it's the most optimal solution - I assume we should add a regression test for this, happy to do so, or if you want to proceed with fixing it with a fresh PR!

@andrewmbenton
Copy link
Collaborator

This is definitely a v1.21.0 regression, related to this PR which added new logic to getTables(): #2674.

I don't know what the appropriate fix is, so will wait for @orisano but in the meantime hopefully falling back to v1.20.0 is a sufficient workaround for you.

@andrewmbenton andrewmbenton added this to the 1.22.0 milestone Sep 14, 2023
@kyleconroy kyleconroy added regression panic 🔧 golang 📚 sqlite and removed triage New issues that hasn't been reviewed labels Sep 14, 2023
orisano added a commit to orisano/sqlc that referenced this issue Sep 14, 2023
close sqlc-dev#2729

ANTLR's API has difficulty handling the case where there is no join_constraint
corresponding to join_operator in join_clause, so an empty join_constraint is accepted.

It is defined as such in the sqlite documentation.
https://www.sqlite.org/syntax/join-clause.html
https://www.sqlite.org/syntax/join-constraint.html
@orisano
Copy link
Contributor

orisano commented Sep 14, 2023

This seems to be caused by the inability to properly handle queries that do not have an ON corresponding to a JOIN.
The workaround is to write an ON corresponding to the JOIN.
Sorry for the inconvenience.

kyleconroy pushed a commit that referenced this issue Sep 14, 2023
close #2729

ANTLR's API has difficulty handling the case where there is no join_constraint
corresponding to join_operator in join_clause, so an empty join_constraint is accepted.

It is defined as such in the sqlite documentation.
https://www.sqlite.org/syntax/join-clause.html
https://www.sqlite.org/syntax/join-constraint.html
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
4 participants