Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(526)

Unified Diff: service/datastore/pls_impl.go

Issue 1494803005: GAE Datastore - Fix derived types not being reflected properly (Closed) Base URL: https://github.com/luci/gae.git@master
Patch Set: Remove debug prints Created 5 years ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
« no previous file with comments | « no previous file | service/datastore/pls_test.go » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: service/datastore/pls_impl.go
diff --git a/service/datastore/pls_impl.go b/service/datastore/pls_impl.go
index 0831f77c748907122678789536aa69fd8ce1866d..2176b7e144ccd9e14c980ad22e7fdbe7dff4990d 100644
--- a/service/datastore/pls_impl.go
+++ b/service/datastore/pls_impl.go
@@ -324,6 +324,8 @@ func (p *structPLS) getMetaFor(idx int) (interface{}, bool) {
val = f.Interface()
if bf, ok := val.(Toggle); ok {
val = bf == On // true if On, otherwise false
+ } else {
+ val = UpconvertUnderlyingType(val)
}
}
}
@@ -383,7 +385,8 @@ func (p *structPLS) SetMeta(key string, val interface{}) (err error) {
if val == nil {
f.Set(reflect.Zero(f.Type()))
} else {
- f.Set(reflect.ValueOf(val))
+ value := reflect.ValueOf(val)
+ f.Set(value.Convert(f.Type()))
}
return nil
}
@@ -584,19 +587,21 @@ func getStructCodecLocked(t reflect.Type) (c *structCodec) {
}
func convertMeta(val string, t reflect.Type) (interface{}, error) {
- switch t {
- case typeOfString:
+ switch t.Kind() {
+ case reflect.String:
return val, nil
+ case reflect.Int, reflect.Int8, reflect.Int16, reflect.Int32, reflect.Int64:
+ if val == "" {
+ return int64(0), nil
+ }
+ return strconv.ParseInt(val, 10, 64)
+ }
+ switch t {
case typeOfKey:
if val != "" {
return nil, fmt.Errorf("key field is not allowed to have a default: %q", val)
}
return nil, nil
- case typeOfInt64:
- if val == "" {
- return int64(0), nil
- }
- return strconv.ParseInt(val, 10, 64)
case typeOfToggle:
switch val {
case "on", "On", "true":
« no previous file with comments | « no previous file | service/datastore/pls_test.go » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698