Skip to content
This repository has been archived by the owner on Nov 8, 2023. It is now read-only.

router handler error: write: key from field *message.Commodity.XXX_NoUnkeyedLiteral: field type not supported for key extraction #14

Closed
happy2048 opened this issue Apr 30, 2019 · 1 comment · Fixed by #18
Labels
question Further information is requested

Comments

@happy2048
Copy link

there is a bug,I use protoc command generate struct like this:

type Commodity struct {
    ....   // other fileds skip 
    XXX_NoUnkeyedLiteral struct{} `json:"-"`
    XXX_unrecognized     []byte   `json:"-"`
   XXX_sizecache        int32    `json:"-"`
}

and I store the instance of Commodity,but get an error: *router handler error: write: key from field message.Commodity.XXX_NoUnkeyedLiteral: field type not supported for key extraction

I find that cckit would also handle the struct fileds like "XXX_NoUnkeyedLiteral" ,"XXX_unrecognized". I think they should be skipped.

I changed the source code file "state/mapping/state_mapping_opt.go" like this:

func attrsPKeyer(attrs []string) InstanceKeyer {
    return func(instance interface{}) (key state.Key, err error) {
        inst := reflect.Indirect(reflect.ValueOf(instance))
        var pkey state.Key
        for _, attr := range attrs {
            v := inst.FieldByName(attr)
            if !v.IsValid() {
                return nil, fmt.Errorf(`%s: %s`, ErrFieldNotExists, attr)
            }
            // **********************************************************************
            //   skip the fields who start with  "XXX_"
            if state,_ := regexp.Match("XXX_.*",[]byte(attr)); state {
                continue
            }
           // **************************************************************************
            if key, err = keyFromValue(v); err != nil {
                return nil, fmt.Errorf(`key from field %s.%s: %s`, mapKey(instance), attr, err)
            }
            pkey = pkey.Append(key)
        }
        return pkey, nil
    }
}
@vitiko
Copy link
Collaborator

vitiko commented May 4, 2019

Could you please send your state mapping configuration ?

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
question Further information is requested
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants