-
-
Notifications
You must be signed in to change notification settings - Fork 177
Do not attempt to traverse the fields of an anonymous pseudo-type #304
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
Conversation
anonymous pseudo-type (i.e. a time.Time)
|
Thanks, I had a look over this code and your investigations helped me get a bit of a better idea about what is going on! I dont particularly like adding more special cases but as you mentioned |
|
Yeah these test failures smell like something else unrelated to what I changed. FWIW the tests in encoding all pass locally on my end. |
|
Regarding the tests if you rebase then they should start passing. |
|
Anything else needed to merge this? |
|
Hey, after thinking about this PR a bit more I am not sure if it should be merged if the driver does not support decoding back into the same data structure. If you have a use case where just the encoding step is important to you let me know, otherwise I think I will wait to merge this. |
|
Sorry, I don't think I clearly explained what works and what doesn't in the original analysis of this fix in #301... So the following works with this patch:
The following does not work with this patch:
I don't really care about the anonymous int case, it was just a curious thing I discovered while investigating my original problem with the anon time.Time, which would be useful to me. I briefly thought they had the same root cause, but they don't. The decoding step clearly doesn't work for the struct-with-anon-int case, but somehow it does work for the struct-with-anon-time case. Below is a sample program that illustrates the behavior with this patch in place: package main
import (
"log"
"time"
r "github.com/dancannon/gorethink"
)
type TimeHolder struct {
time.Time
}
type ANumber struct {
int
}
type Post struct {
Title string
When TimeHolder
Value ANumber
}
func main() {
p := Post{
Title: "A test",
When: TimeHolder{time.Now()},
Value: ANumber{100},
}
log.Printf("%+v\n", p)
session, err := r.Connect(r.ConnectOpts{
Address: "localhost:28015",
Database: "test",
})
if err != nil {
log.Fatal(err)
}
response, err := r.DB("test").Table("time_test").Delete().RunWrite(session)
if err != nil {
log.Fatal(err)
}
log.Printf("Deleted: %d\n", response.Deleted)
_, err = r.DB("test").Table("time_test").Insert(p).RunWrite(session)
if err != nil {
log.Fatal(err)
}
cursor, err := r.DB("test").Table("time_test").Run(session)
if err != nil {
log.Fatal(err)
}
if err := cursor.One(&p); err != nil {
log.Fatal(err)
}
log.Printf("%+v\n", p)
}Output: Thanks again for reviewing, appreciate the help! Eddy |
Do not attempt to traverse the fields of an anonymous pseudo-type
(i.e. a time.Time)
#301
Please review, expert input is needed :-)