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

Implicit initialization of lib/pq messes with other imports #18

Open
anaulin opened this issue Mar 15, 2016 · 2 comments
Open

Implicit initialization of lib/pq messes with other imports #18

anaulin opened this issue Mar 15, 2016 · 2 comments

Comments

@anaulin
Copy link

anaulin commented Mar 15, 2016

Hi there, thanks for the handy library!

Since I was already using github.com/lib/pq in my app, when I added a dependency on github.com/antonlindstrom/pgstore I got the following runtime error:

panic: sql: Register called twice for driver postgres

goroutine 1 [running]:
panic(0x420ec0, 0xc820208e30)
    /usr/local/Cellar/go/1.6/libexec/src/runtime/panic.go:464 +0x3e6
database/sql.Register(0x5a78c0, 0x8, 0x9b2b58, 0x84dd30)
    /usr/local/Cellar/go/1.6/libexec/src/database/sql/sql.go:45 +0x181
github.com/bolt-data/boltapp/vendor/github.com/lib/pq.init.1()
    /Users/anaulin/src/github.com/bolt-data/boltapp/vendor/github.com/lib/pq/conn.go:44 +0x71
github.com/bolt-data/boltapp/vendor/github.com/lib/pq.init()
    /Users/anaulin/src/github.com/bolt-data/boltapp/vendor/github.com/lib/pq/user_posix.go:24 +0x4b0
github.com/bolt-data/boltapp/db.init()
    /Users/anaulin/src/github.com/bolt-data/boltapp/db/connection.go:27 +0x59
github.com/bolt-data/boltapp/handlers.init()
    /Users/anaulin/src/github.com/bolt-data/boltapp/handlers/template_util.go:28 +0x5b
main.init()

I can work around this issue by removing my own import of github.com/lib/pq but it feels a little messy, for a couple of reasons:

  1. It is no longer explicit in my code which Postgres driver is being used and where
  2. Some other dependency that also registers lib/pq will mess with things
@elithrar
Copy link
Contributor

Agreed that it is undesirable behaviour.

It'd be a breaking change for existing users who only use this lib (and not Postgres elsewhere, which would be weird, but not unheard of). You can't conditionally import either.

TL;DR: Probably a change worth making.

@antonlindstrom
Copy link
Owner

I agree, this is something that I think that we should update and document.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants