Why is Go trying to upgrade my go.mod to Go 1.21?

Featured image for sharing metadata for article

On oapi-codegen we recently had a report that Go 1.21 results in go test being unable to run without having go mod tidy'd the project.

If you're running Go 1.21:

$ go version
go version go1.21.0 linux/amd64

Then checking out the project (as of the latest commit and running make tidy shows the following diff:

diff --git go.mod go.mod
index dd8b906..2122b0e 100644
--- go.mod
+++ go.mod
@@ -1,6 +1,8 @@
 module github.com/deepmap/oapi-codegen

-go 1.20
+go 1.21
+
+toolchain go1.21.0

Through discussion in the Go community (Gopher) Slack, it appears that this is due to one of the modules in my dependency tree using Go 1.21, and therefore Go is upgrading the whole project to Go 1.21.

As noted in the Go 1.21 release notes, the go directive now defines an explicit minimum, whereas before it could be possible to try and build a future version of Go code, and maybe it would just work, or fail.

I've blogumented that process to determine the versions in a separate blog post.

But if you're seeing this issue, your best course of action is to take the changes and upgrade the whole project to 1.21.

Written by Jamie Tanna's profile image Jamie Tanna on , and last updated on .

Content for this article is shared under the terms of the Creative Commons Attribution Non Commercial Share Alike 4.0 International, and code is shared under the Apache License 2.0.

#blogumentation #go.

This post was filed under articles.

Interactions with this post

Interactions with this post

Below you can find the interactions that this page has had using WebMention.

Have you written a response to this post? Let me know the URL:

Do you not have a website set up with WebMention capabilities? You can use Comment Parade.