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
Fix cases where the fix for issue260 was not enough #261
Conversation
Why is p.typesPkg.Use() not enough in the unmarshaler? |
typesPkg is the gogoprotobuf types, I need to signal that I need the time package. This changes are not because of the line after but because of the line before. |
Ok yes, my bad. What about all the other plugins? If timesPkg isn't an option, could we maybe let generator.UseTime() return a string "time" |
I can do the second option. I review the rest of the plugins, but I was looking for uses of Thank you! |
No! Thank YOU very much. |
My main problem is that type SingleType interface {
Use() string
}
type singleType string
func (s *singleType) Use() string {
...
}
type singleTypeWithSideEffect struct {
name string
fn . func()
}
func (s *singleType) Use() string {
// Sideeffect
} The refactor is quite big, but it would allow us to manage this deps in a better way. |
I am busy making a simpler fix. Basically only when time is imported I also add the |
Sorry that I stepped in, but I don't like having things broken and it was quicker to fix it myself than to communicate. |
I have a fix for this case I'll be submitting tomorrow. But improving testing related to #262, I saw another problem with stdtime. More on it tomorrow, been a long day navigating |
cb8d1f4
to
aa05f33
Compare
Rebasing... |
aa05f33
to
afccd71
Compare
👍 for the work here, good job! |
Ooook, so here it goes a summary of yesterday navigating protobuf. Initial caseMy first attempt was to track where the import was lacking and making sure it would not happen again. The thing is that, for tracking that imports are done correctly, one cannot keep all the cases in one proto test since you can even have no individual case right but the proto as a whole can pass (more on this, later). Some of the main problems with generating a message is that the Then I considered applying the refactor I talked about here #261 (comment) but changing typename from Therefore, I went to a The case of maps with stdtime/stddurationWhen I started working on the fix, the first thing I did was splitting stdtype test in several tests. This helped me debugging the issue and showed a different issue with stdtime. The following paragraphs will be copypasted in a new issue. If we have a field whose type is a map with
|
@@ -2865,12 +2863,14 @@ func (g *Generator) generateMessage(message *Descriptor) { | |||
val = "*c" | |||
} else if gogoproto.IsStdTime(field) { | |||
pkg := g.useTypes() | |||
g.UseTime() |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Why do we need to UseTime twice?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think it was a problem with my rebase.
@@ -2879,12 +2879,14 @@ func (g *Generator) generateMessage(message *Descriptor) { | |||
val = "c" | |||
} else if gogoproto.IsStdDuration(field) { | |||
pkg := g.useTypes() | |||
g.UseTime() | |||
g.P(`if err != nil {`) | |||
g.In() | |||
g.P(`return true, err`) | |||
g.Out() | |||
g.P(`}`) | |||
g.P(`c := new(time.Duration)`) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
What about g.P(c := new(
, g.UseTime(), .time.Duration)
)
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
On it.
import "google/protobuf/duration.proto"; | ||
|
||
message MapStdTypes { | ||
//map<int32,google.protobuf.Duration> duration = 4 [(gogoproto.stdduration) = true]; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Should this be commented?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
?
There is a lot of tests here, which is great, but it also pointing to how complex is issue and can become. The only downsides are:
|
Great writeup of the issues by the way. |
@awalterschulze I understand that it would be a nightmare to maintain but the bugs are still there no matter how. The best way would be to use Maybe a new kind of test that just generates lots and lots of single-field proto tests is needed. I don't know. The code needs a huge refactor. And I don't mean gogo/protobuf but golang/protobuf. Please, feel free to drop this PR. None of my feelings will be hurt for sure. I went on with this so your comment here was a reality. Proteus is working, which was my main concern. If the generated files have more imports than needed, it is no problem for me. Thanks for reviewing all my PRs! |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I didn't know we had so many problems.
Wow thanks a lot for bringing this to light.
Now I am unsure whether my or your fix would be best.
So are the commented ones still failing, even with your fixes?
On the one hand I wish I wrote everything from scratch, but on the other I am not in control of the serialization format, so merging in changes makes it easier to stay accurate to the format. Being a fork can be frustrating and great :)
Thanks for the support. I really appreciate it.
@@ -2879,12 +2877,13 @@ func (g *Generator) generateMessage(message *Descriptor) { | |||
val = "c" | |||
} else if gogoproto.IsStdDuration(field) { | |||
pkg := g.useTypes() | |||
g.UseTime() |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
UseTime is already called below, so this one is redundant
@@ -2748,6 +2745,7 @@ func (g *Generator) generateMessage(message *Descriptor) { | |||
} else if gogoproto.IsStdDuration(field) { | |||
pkg := g.useTypes() | |||
if gogoproto.IsNullable(field) { | |||
g.UseTime() |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Do we need UseTime here?
import "google/protobuf/duration.proto"; | ||
|
||
message MapStdTypes { | ||
//map<int32,google.protobuf.Duration> duration = 4 [(gogoproto.stdduration) = true, (gogoproto.nullable) = false]; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Should this be commented?
import "google/protobuf/duration.proto"; | ||
|
||
message MapStdTypes { | ||
//map<int32,google.protobuf.Duration> duration = 4 [(gogoproto.stdduration) = true]; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
?
import "google/protobuf/timestamp.proto"; | ||
|
||
message MapStdTypes { | ||
//map<int32,google.protobuf.Timestamp> timestamp = 2 [(gogoproto.stdtime) = true, (gogoproto.nullable) = false]; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Should this be commented?
import "google/protobuf/timestamp.proto"; | ||
|
||
message MapStdTypes { | ||
//map<int32,google.protobuf.Timestamp> timestamp = 2 [(gogoproto.stdtime) = true]; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Should this be commented?
6e5606d
to
57ba2fa
Compare
Fix what I could fix. The commented tests have never been working, not even before I started contributing. The problem is that in a map, the keys and values are not represented by |
57ba2fa
to
07e2f57
Compare
Rebased |
Sorry for the delay. |
NP |
This was really hard to find, but this should fix it |
False alarm :( |
This should be better 83faaee |
So I think all the bugs that this pull request is pointing out has been fixed. |
In some cases with gogoslick, time is not being imported. If the import is generated for one case but not for the others, having the implementation in the same package would masquerade the bug. Therefore, I've added one package for each of them. This bug is not manifested if tests are generated, therefore these packages are not gentested (but a `go test ./...` would fail given there is an import missing).
07e2f57
to
b200b17
Compare
Rebased your changes. |
And I see all the maps are uncommented as well. |
I am going to create a new extension for making nullable the value types in a map. Can I close this or are you still interested on something from here? Thank you! |
Yes I think you can close this. I am interested in the new usecase with maps? Currently I am holiday for a few weeks. |
Some people needs to represent |
Isn't that already possible for messages or what is Otherthing
…On Fri, 28 Apr 2017, 17:19 Sergio Arbeo, ***@***.***> wrote:
Closed #261 <#261>.
—
You are receiving this because you were mentioned.
Reply to this email directly, view it on GitHub
<#261 (comment)>, or mute the
thread
<https://github.com/notifications/unsubscribe-auth/ABvsLXsOYP3Vp9SZqwyu883ayN0E3p8zks5r0gOcgaJpZM4MAo2Q>
.
|
Sorry, it was a typo |
Doesn't nullable false work?
…On Sat, 29 Apr 2017, 14:02 Sergio Arbeo, ***@***.***> wrote:
Sorry, it was a typo map[Something]OtherThing.
—
You are receiving this because you were mentioned.
Reply to this email directly, view it on GitHub
<#261 (comment)>, or mute
the thread
<https://github.com/notifications/unsubscribe-auth/ABvsLQsF1oXgb6_voPZVw_VycXJd3escks5r0ybugaJpZM4MAo2Q>
.
|
It does, thank you! |
Reopening this since we have found a similar bug again. I'll dive tomorrow or next week to see what happened, if was something that I did not test or a regression. Thank you! |
hello? |
Closing this as I don't use protobuf anymore. Thank you! |
The previous fix had some corner cases not covered by the
useTime
fix, sincetime.Time
might only be used in the unmarhsaler plugin.This PR makes
useTime
public and adds it to the lines ofunmarshaler
where it is needed.Sorry, for having to do this fix.