Skip to content

Password in Config is ignored #1301

@SchaeferDurag

Description

@SchaeferDurag

Good day and thanks for this great package.

I've just encountered an issue with the connection config.

In version v1.11.2 if you assign a password via the Config fields, it is ignored.

Simplified example with error handling removed:

cfg, _ := pq.NewConfig("")
cfg.User = "myuser"
cfg.Password = "secret"
connCfg, _ := pq.NewConnectorConfig(cfg)
db := sql.OpenDB(connCfg)
err := db.Ping()
if err != nil {
   // we are now here because the password is not assigned
}

Digging a bit deeper, in conn.go, func DialOpen(...):

		cn.cfg.Password = pgpass.PasswordFromPgpass(cn.cfg.Passfile, cn.cfg.User, cn.cfg.Password,
			cn.cfg.Host, strconv.Itoa(int(cn.cfg.Port)), cn.cfg.Database, cn.cfg.isset("password"))

cn.cfg.isset("password") <-- this is false

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions