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

Getting a reflection panic when trying to save a record with a belongs_to pointer #298

Closed
akostibas opened this issue Nov 13, 2018 · 0 comments
Assignees
Labels
bug Something isn't working

Comments

@akostibas
Copy link
Contributor

Description

We are trying to update from 4.8.7 to 4.9.0.

I have a model that uses pointers for relational fields that are optional (nullable.) For example:

type TransportationOffice struct {
    ID               uuid.UUID             `json:"id" db:"id"`                                             
    ShippingOfficeID *uuid.UUID            `json:"shipping_office_id" db:"shipping_office_id"`             
    ShippingOffice   *TransportationOffice `belongs_to:"transportation_offices"`
    Name             string                `json:"name" db:"name"`
    Address          Address               `belongs_to:"address"`
    ...

Full source here

Now, when trying to save this model with a null value in the ShippingOffice field, I'm getting a panic in the reflection package:

panic: reflect: call of reflect.Value.FieldByName on zero Value [recovered]
	panic: reflect: call of reflect.Value.FieldByName on zero Value

goroutine 66 [running]:
testing.tRunner.func1(0xc42058c000)
	/usr/local/Cellar/go@1.10/1.10.4/libexec/src/testing/testing.go:742 +0x29d
panic(0x18388a0, 0xc420671320)
	/usr/local/Cellar/go@1.10/1.10.4/libexec/src/runtime/panic.go:502 +0x229
reflect.flag.mustBe(0x0, 0x19)
	/usr/local/Cellar/go@1.10/1.10.4/libexec/src/reflect/value.go:207 +0xb5
reflect.Value.FieldByName(0x0, 0x0, 0x0, 0x191afb0, 0x2, 0x0, 0x0, 0x0)
	/usr/local/Cellar/go@1.10/1.10.4/libexec/src/reflect/value.go:835 +0x4c
github.com/transcom/mymove/vendor/github.com/gobuffalo/pop/associations.(*belongsToAssociation).BeforeSetup(0xc42066e300, 0x185b940, 0x0)
	/Users/alexi/Documents/projects/golang/src/github.com/transcom/mymove/vendor/github.com/gobuffalo/pop/associations/belongs_to_association.go:113 +0x13e
github.com/transcom/mymove/vendor/github.com/gobuffalo/pop.(*Connection).Create.func1.1(0xbef2a84560ba7cae, 0x2a399c4b)
	/Users/alexi/Documents/projects/golang/src/github.com/transcom/mymove/vendor/github.com/gobuffalo/pop/executors.go:136 +0x8b7
github.com/transcom/mymove/vendor/github.com/gobuffalo/pop.(*Connection).timeFunc(0xc4200f53e0, 0x191eacb, 0x6, 0xc420d2b790, 0xc42046b680, 0xc420d2b7c8)
	/Users/alexi/Documents/projects/golang/src/github.com/transcom/mymove/vendor/github.com/gobuffalo/pop/connection.go:206 +0x50
github.com/transcom/mymove/vendor/github.com/gobuffalo/pop.(*Connection).Create.func1(0xc42052ba70, 0x23ab400, 0x0)
	/Users/alexi/Documents/projects/golang/src/github.com/transcom/mymove/vendor/github.com/gobuffalo/pop/executors.go:112 +0xa7
github.com/transcom/mymove/vendor/github.com/gobuffalo/pop.(*Model).iterate(0xc42052ba70, 0xc42052bad0, 0xc420d2b898, 0x156db9a)
	/Users/alexi/Documents/projects/golang/src/github.com/transcom/mymove/vendor/github.com/gobuffalo/pop/model.go:197 +0x20b
github.com/transcom/mymove/vendor/github.com/gobuffalo/pop.(*Connection).Create(0xc4200f53e0, 0x18fc7c0, 0xc42046b680, 0x0, 0x0, 0x0, 0x0, 0xc420d2b980)
	/Users/alexi/Documents/projects/golang/src/github.com/transcom/mymove/vendor/github.com/gobuffalo/pop/executors.go:111 +0xf0
github.com/transcom/mymove/vendor/github.com/gobuffalo/pop.(*Connection).ValidateAndCreate(0xc4200f53e0, 0x18fc7c0, 0xc42046b680, 0x0, 0x0, 0x0, 0x0, 0xc4200a4000, 0xc420d2b980)
	/Users/alexi/Documents/projects/golang/src/github.com/transcom/mymove/vendor/github.com/gobuffalo/pop/executors.go:100 +0x111
github.com/transcom/mymove/pkg/testdatagen.mustCreate(0xc4200f53e0, 0x18fc7c0, 0xc42046b680)
	/Users/alexi/Documents/projects/golang/src/github.com/transcom/mymove/pkg/testdatagen/shared.go:70 +0x6b
github.com/transcom/mymove/pkg/testdatagen.MakeTransportationOffice(0xc4200f53e0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, ...)
	/Users/alexi/Documents/projects/golang/src/github.com/transcom/mymove/pkg/testdatagen/make_transportation_office.go:24 +0x21d

It looks like some work was done in/around the belongs_to_association.go code recently: #199 that may be related.

Happy to provide more details if necessary.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

No branches or pull requests

2 participants