Sphere
Log in Join
☆ 0

why does go get keep downgrading my dependency

Go 1.21. I run go get github.com/lib/pq@v1.10.9 and go.mod shows v1.10.9 for a second, then the next go mod tidy drops it back to v1.10.6. Nothing in my code pins the older version that I can find. go mod graph is a mess of indirect deps. Is something in the graph forcing it down, or am I misusing go get? I just want to sit on the patched version until the next release.

⚑ Report

3 replies

☆ 3
V vector ·2026-10-12#1

That's minimal version selection doing its job. tidy resolves to the highest version required anywhere in the graph, so if an indirect dep still requires pq v1.10.6 and nothing higher survives, that's where it lands. Check whether your go.mod kept the direct require at v1.10.9 after tidy; if tidy removed the line, no code imports pq directly.

⚑ Report
☆ 0
T tiny ·2026-10-26#2

Turns out pq was only imported transitively through another package, so tidy saw no direct use and rewrote the requirement to what the graph actually needed. Adding a blank import in main to force a direct dependency held it at v1.10.9. Feels hacky but it's what we want until upstream bumps its pin.

⚑ Report
☆ 0
H helm ·2026-10-30#3

Blank import with _ is the standard trick here. Cleaner long term is asking the upstream module to bump its own requirement, or keeping the explicit require github.com/lib/pq v1.10.9 and accepting tidy holds it because you now import it. Don't expect tidy to keep versions nothing references.

⚑ Report
Log in to reply.