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

Crash if asked to replace a value which can be NULL #6

Open
PatrickLerner opened this issue Jan 27, 2020 · 8 comments · May be fixed by #7
Open

Crash if asked to replace a value which can be NULL #6

PatrickLerner opened this issue Jan 27, 2020 · 8 comments · May be fixed by #7

Comments

@PatrickLerner
Copy link

Given a database like

DROP TABLE IF EXISTS `test`;
CREATE TABLE `test` (
`email` varchar(255),
);
INSERT INTO `test` VALUES ('foo'), (NULL), ('hodger');

if you use a config like

{
  "patterns": [
    {
      "tableName": "test",
      "fields": [
        {
          "field": "email",
          "position": 1,
          "type": "email",
          "constraints": null
        }
      ]
    }
  ]
}

the tool will crash with a panic:

panic: interface conversion: sqlparser.Expr is *sqlparser.NullVal, not *sqlparser.SQLVal

goroutine 35 [running]:
main.modifyValues(0xc0003f6060, 0x3, 0x4, 0xc00008e2f8, 0x4, 0xc0001e6000, 0x1, 0x4, 0x0, 0x0, ...)
	/Users/aang/Code/golang/src/github.com/humanmade/go-anonymize-mysqldump/anonymize-mysqldump.go:299 +0x572
main.applyConfigToInserts(0xc00041a0b0, 0xc0001e4000, 0x1, 0x4, 0x0, 0x0, 0x0)
	/Users/aang/Code/golang/src/github.com/humanmade/go-anonymize-mysqldump/anonymize-mysqldump.go:277 +0x1f9
main.applyConfigToParsedLine(0x126f020, 0xc00041a0b0, 0xc0001e4000, 0x1, 0x4, 0x0, 0x0, 0x0, 0x0)
	/Users/aang/Code/golang/src/github.com/humanmade/go-anonymize-mysqldump/anonymize-mysqldump.go:250 +0x68
main.processLine(0xc0001cc1c0, 0x36, 0xc0001e4000, 0x1, 0x4, 0x0, 0x0)
	/Users/aang/Code/golang/src/github.com/humanmade/go-anonymize-mysqldump/anonymize-mysqldump.go:218 +0x2c1
main.processInput.func1(0xc00008e320, 0xc0001e4000, 0x1, 0x4, 0xc0003f20c0, 0xc0001cc1c0, 0x36)
	/Users/aang/Code/golang/src/github.com/humanmade/go-anonymize-mysqldump/anonymize-mysqldump.go:194 +0xab
created by main.processInput
	/Users/aang/Code/golang/src/github.com/humanmade/go-anonymize-mysqldump/anonymize-mysqldump.go:192 +0x41c

If NULL does not appear, it works fine.

@NikolaiGulatz NikolaiGulatz linked a pull request May 7, 2020 that will close this issue
@NikolaiGulatz
Copy link

@PatrickLerner please see my PR which fixes this issue by ignoring NULL values in transformable fields.

@jasperoosthoek
Copy link

I'm running into this issue right now and would appreciate if this PR gets merged!

@fadiadawi
Copy link

fadiadawi commented Feb 11, 2021

I used this PR and still getting the same error. Please help. I am building it on my mac using the following command
GOOS=linux GOARCH=amd64 go build -v github.com/NikolaiGulatz/go-anonymize-mysqldump
The build is success but same issue with the null values

@PatrickLerner
Copy link
Author

Hey @fadiadawi,

When I compiled the binary from Nikolai's branch, I did it like so:

docker run -e GOOS=linux -e GOARCH=amd64 -v /tmp/crosstest:/go/bin golang bash -c "git clone 'https://github.com/NikolaiGulatz/go-anonymize-mysqldump.git' /go/src/go-anonymize-mysqldump && cd /go/src/go-anonymize-mysqldump && git checkout fix-for-null-values && go get . && go build"

I think the issue is that go does not check out the feature branch? I also remember that this was explicitly not a feature in go to build it from a branch for some reason or another (I don't use go usually).

Hope it helps 🤞

@fadiadawi
Copy link

fadiadawi commented Feb 11, 2021 via email

@PatrickLerner
Copy link
Author

Are you trying to run a linux binary on mac?

Maybe try this or similar:

docker run -e GOOS=darwin -e GOARCH=amd64 -v /tmp/crosstest:/go/bin golang bash -c "git clone 'https://github.com/NikolaiGulatz/go-anonymize-mysqldump.git' /go/src/go-anonymize-mysqldump && cd /go/src/go-anonymize-mysqldump && git checkout fix-for-null-values && go get . && go build"

if you need a mac binary :)

@fadiadawi
Copy link

fadiadawi commented Feb 11, 2021 via email

@fadiadawi
Copy link

fadiadawi commented Feb 11, 2021 via email

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

Successfully merging a pull request may close this issue.

4 participants