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

Default value should not be nil #2995

Merged
merged 7 commits into from
Feb 14, 2019
Merged

Conversation

srfrog
Copy link
Contributor

@srfrog srfrog commented Feb 8, 2019

types.Marshal() expects vars to have non-nil values, this change
set empty string as the default value for a referenced empty
var. This should prevent nil-reference panic in types.Marshal().


This change is Reviewable

types.Marshal expects vars to have non-nil values, this change
set empty string as the default value for a referenced aggregate
value. This should prevent nil-reference panic in types.Marshal.
@martinmr
Copy link
Contributor

martinmr commented Feb 8, 2019

This is breaking one of the tests.

@srfrog
Copy link
Contributor Author

srfrog commented Feb 8, 2019

Yes, I'm still working on that. Thanks

@srfrog srfrog closed this Feb 8, 2019
srfrog added 2 commits February 8, 2019 14:54
Value var aggregations use nil values for an optimization, so don't
assign a value to defaults.
The marshaling of default value vars to string causes panic because
the incoming value is nil. This affects a narrow case so we check
that in fact it's a default value var and marshal to empty string.
In theory nothing should be nil by the time we Marshal, but it's
an edge case.
@srfrog srfrog requested a review from a team February 11, 2019 18:10
Copy link
Contributor

@manishrjain manishrjain left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

https://play.golang.org/p/7Q3UfxhXE11

Let's switch all the conversions to use the second argument, so instead of asserting a certain type, Go would check and respond whether the assert was successful or not.

Reviewable status: 0 of 1 files reviewed, all discussions resolved

@srfrog
Copy link
Contributor Author

srfrog commented Feb 12, 2019

I can make that change in types.Marshal(), but the bug is an edge-case of the default value vars. I don't think returning error will be a good thing there.

srfrog added 2 commits February 11, 2019 19:02
If we are trying to mashal a nil value, return the zero value
instead of crashing on nil reference.
@srfrog
Copy link
Contributor Author

srfrog commented Feb 12, 2019

Much better solution now in place.

Copy link
Contributor

@manishrjain manishrjain left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

:lgtm: One comment.

Reviewed 1 of 1 files at r3.
Reviewable status: all files reviewed, 1 unresolved discussion (waiting on @srfrog)


types/conversion.go, line 344 at r3 (raw file):

	res := &to.Value

	// This is a default value from sg.fillVars, don't convert it's empty.

For completeness, can you also check that to is not nil. And if it is, return an error.

Copy link
Contributor Author

@srfrog srfrog left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Reviewable status: 0 of 1 files reviewed, 1 unresolved discussion (waiting on @manishrjain)


types/conversion.go, line 344 at r3 (raw file):

Previously, manishrjain (Manish R Jain) wrote…

For completeness, can you also check that to is not nil. And if it is, return an error.

Done.

@srfrog srfrog merged commit d9b1725 into master Feb 14, 2019
@srfrog srfrog deleted the srfrog/issue-2980_crash_with_panic branch February 14, 2019 01:40
dna2github pushed a commit to dna2fork/dgraph that referenced this pull request Jul 19, 2019
* query/query.go: default value should not be nil

types.Marshal expects vars to have non-nil values, this change
set empty string as the default value for a referenced aggregate
value. This should prevent nil-reference panic in types.Marshal.

* query/query.go: retract default value change it breaks aggs.

Value var aggregations use nil values for an optimization, so don't
assign a value to defaults.

* types/conversion.go: add exception in Marshal for default->string

The marshaling of default value vars to string causes panic because
the incoming value is nil. This affects a narrow case so we check
that in fact it's a default value var and marshal to empty string.
In theory nothing should be nil by the time we Marshal, but it's
an edge case.

* wrong issue referenced in comments

* types/conversion.go: general case in nil value mashaling

If we are trying to mashal a nil value, return the zero value
instead of crashing on nil reference.

* types/conversion.go: replace the original to-value

* types/conversion.go: added check for Marshal to nil object
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Development

Successfully merging this pull request may close these issues.

3 participants