성능상의 이유로 Google AppEngine 프로젝트에 모듈을 쓰고 있는데 데이터 저장소에있는 엔티티 중 일부에서 읽을 수 있어야합니다. . 내가 파이썬에서 내장 된 개체를 읽을 수 있도록 이동 코드를 썼다 그러나 나는 다음과 같은 오류가 무엇입니까 : 파이썬에서Go의 Python 프로젝트에서 데이터 스토어 엔티티로드 중첩 된 구조체 슬라이스 조각 오류
datastore: flattening nested structs leads to a slice of slices: field "Messages"
모델 정의 :
class ModelB(ndb.Model):
msg_id = ndb.StringProperty(indexed=False)
cat_ids = ndb.StringProperty(repeated=True, indexed=False)
list_ids = ndb.StringProperty(repeated=True, indexed=False)
default_list_id_index = ndb.IntegerProperty(indexed=False)
class ModelA(ndb.Model):
date_join = ndb.DateTimeProperty(auto_now_add=True)
name = ndb.StringProperty()
owner_salutation = ndb.StringProperty(indexed=False)
owner_email_address = ndb.StringProperty()
logo_url = ndb.StringProperty(indexed=False)
...
messages = ndb.LocalStructuredProperty(ModelB, name='bm', repeated=True)
그리고 이동의를 :
type ModelB struct {
MessageID string `datastore:"msg_id,noindex"`
CategoryIDs []string `datastore:"cat_ids,noindex"`
ListIDs []string `datastore:"list_ids,noindex"`
DefaultListIDIndex int `datastore:"default_list_id_index,noindex"`
}
type ModelA struct {
DateJoin time.Time `datastore:"date_join,"`
Name string `datastore:"name,"`
OwnerSalutation string `datastore:"owner_salutation,noindex"`
OwnerEmailAddress string `datastore:"owner_email_address,"`
LogoURL string `datastore:"logo_url,noindex"`
Messages []ModelB `datastore:"bm,"`
}
내가 여기서 잘못하고있는 것이 있습니까? Go와 Python 모델 정의 간의 기능 불일치입니까?
import pb "appengine_internal/datastore"
import proto "code.google.com/p/goprotobuf/proto"
type ModelA struct {
DateJoin time.Time `datastore:"date_join,"`
Name string `datastore:"name,"`
OwnerSalutation string `datastore:"owner_salutation,noindex"`
OwnerEmailAddress string `datastore:"owner_email_address,"`
LogoURL string `datastore:"logo_url,noindex"`
Messages []ModelB `datastore:"-"`
}
// Load is implemented for the PropertyLoaderSaver interface.
func (seller *ModelA) Load(c <-chan datastore.Property) error {
f := make(chan datastore.Property, 100)
for p := range c {
if p.Name == "bm" {
var val pb.EntityProto
err := proto.Unmarshal([]byte(p.Value.(string)), &val)
if err != nil {
return err
}
//TODO: Store result as a new ModelB
} else {
f <- p
}
}
close(f)
return datastore.LoadStruct(seller, f)
}
을하지만 다음과 같은 오류가 나타납니다 : 이 proto: required field "{Unknown}" not set
다른 점도 있습니다. 파이썬에서는 반복 된 하위 속성을 포함하는 반복 된 StructuredProperty를 가질 수 없습니다 (Go와 동일한 제약 조건). 파이썬에서이 문제를 해결 한 이유는 LocalStructuredProperty를 사용했기 때문입니다. LocalStructuredProperty는 StructuredProperty와는 다른 인코딩을 사용합니다. 데이터를 최상위 엔티티가 인코딩 된 것과 같은 방식으로 인코딩 된 바이트 문자열로 저장합니다. 하지만 Go 코드는 StructuredProperty를 사용하는 것과 동일합니다. 바이트 배열의 배열로 선언하고이를 별도로 디코딩 할 수 있습니까? 이것이 파이썬에서 일어나는 일이기 때문입니다. –
'ModelB' 대신'ModelA'의'Messages'를'[] string'으로 바꿀 수 있습니다 만, 나는 protobuffer 인코딩 된 문자열로 가정합니다. Go/python이 protobuffers를 인 코드/디코 드하는 방법에 대해 최선을 다했지만 그 중 일부는 나를 넘어선 것입니다. 나는 개념이 단순해야한다고 생각하고, 인코딩 된 문자열을 새로운 protobuffer로 처리하여 정상적인 프로세스를 해독 할 수는 있지만,이 프로세스가 충분히 사용되면 내보내고 다시 만들 수 있는지 확실하지 않습니다. 이것을 달성하는 방법에 대한 아이디어가 있습니까? – someone1