golang/dep

dep revision constraint doesn't appear to work

davecheney opened this issue · 8 comments

What version of dep are you using (dep version)?

% cd $GOPATH/src/github.com/golang/dep && git describe --tags
v0.3.1-66-gac1a162

What dep command did you run?

% grep -a2 apimach Gopkg.toml 

[[constraint]]
  name="k8s.io/apimachinery"
  revision="917740426ad66ff818da4809990480bcc0786a77"

dep ensure -v

What did you expect to see?

What did you see instead?

(22)  ? attempt k8s.io/apimachinery with 26 pkgs; 4 versions to try
(23)      try k8s.io/apimachinery@master
(23)  ✓ select k8s.io/apimachinery@master w/42 pkgs

^ dep selected k8s.io/apimachinery@master, it should have selected k8s.io/apimachinery@917740426ad66ff818da4809990480bcc0786a77

heeeyooo! most probably, k8s.io/apimachinery is a transitive dependency, so your constraints don't affect it. we've had an issue open forever to warn about ineffectual constraints, #302, as it seemed like a good-ish task for someone new to take on. but this bites too many people for too long - i should maybe just bang out the fix.

#1124 has a bunch of discussion on allowing constraints to operate transitively. (not) coincidentally, k8s is at the center of that one, too.

I think it's a bigger problem than a case of transitive dependency (if I understand it correctly).

Here, I am directly overriding aws-sdk-go to a lower version of 1.10.19 and dep seems to be ignoring it:

mve@mybox test $ egrep -v "^#|^$" Gopkg.toml
[[override]]
  name = "github.com/aws/aws-sdk-go"
  version = "1.10.19"


mve@mybox test $ dep ensure -update github.com/aws/aws-sdk-go
mve@mybox test $ dep status
PROJECT                          CONSTRAINT    VERSION  REVISION  LATEST   PKGS USED
github.com/aws/aws-sdk-go        * (override)  v1.12.7  7607418   7607418  27
github.com/go-ini/ini            *             v1.28.2  20b96f6   20b96f6  1
github.com/jmespath/go-jmespath  *                      0b12d6b            1
mve@mybox test $


mve@mybox test $ dep version
dep:
 version     : devel
 build date  :
 git hash    :
 go version  : go1.9
 go compiler : gc
 platform    : darwin/amd64

mve@mybox test $ type dep
dep is hashed (/usr/local/bin/dep)

mve@mybox test $ ls -l /usr/local/bin/dep
lrwxr-xr-x  1 mve  admin  27 Oct  4 15:33 /usr/local/bin/dep -> ../Cellar/dep/0.3.1/bin/dep
mve@mybox test $

It's a simple main.go test app:

total 143888
-rw-r--r--  1 mve  staff      1220 Oct 10 08:50 Gopkg.lock
-rw-r--r--  1 mve  staff       608 Oct  9 10:04 Gopkg.toml
-rw-r--r--  1 mve  staff      1990 Oct  9 11:19 main.go
-rwxr-xr-x  1 mve  staff  10032724 Oct  9 11:19 tst-aws-s3
drwxr-xr-x  3 mve  staff       102 Oct 10 08:50 vendor
mve@mybox test $ cat main.go
package main

import (
	"fmt"
	"io"
	"os"

	"github.com/aws/aws-sdk-go/aws"
	"github.com/aws/aws-sdk-go/aws/awserr"
	"github.com/aws/aws-sdk-go/aws/session"
	"github.com/aws/aws-sdk-go/service/s3"
	"github.com/aws/aws-sdk-go/service/s3/s3manager"
)
...
...

Solution (as noted #1207 (comment)) is to switch to revision override:

mve@mybox test $ egrep -v "^#|^$" Gopkg.toml
[[override]]
  name = "github.com/aws/aws-sdk-go"
  revision = "75d583c2afd3807d4d3f24b31b06feebb8849242"


mve@mybox test $ dep ensure -update github.com/aws/aws-sdk-go
Gopkg.lock is out of sync with Gopkg.toml or the project's imports. Run "dep ensure" to resync them first before running "dep ensure -update"
mve@mybox test $ dep ensure
mve@mybox test $ dep status
PROJECT                          CONSTRAINT          VERSION  REVISION  LATEST   PKGS USED
github.com/aws/aws-sdk-go        75d583c (override)           75d583c            27
github.com/go-ini/ini            *                   v1.28.2  20b96f6   20b96f6  1
github.com/jmespath/go-jmespath  *                            0b12d6b            1
mve@mybox test $

@sdboyer I see, so to get it to pin at a certain version I would have to switch to version = "=1.10.19". Thank you -- that was a classic RTFM case on my part :) OTOH, = could have been a nicer default to alleviate these types of questions.

That's true, I forgot about Gopkg.lock. Thank you.