Skip to content

Commit 2dedbf3

Browse files
authored
Merge pull request #103 from anyproto/go-1539-error-object-is-not-an-object-type
fix objectShow with objects of removed types
2 parents 14497bb + 15b81dd commit 2dedbf3

File tree

3 files changed

+25
-6
lines changed

3 files changed

+25
-6
lines changed

core/block/editor/smartblock/smartblock.go

+1
Original file line numberDiff line numberDiff line change
@@ -445,6 +445,7 @@ func (sb *smartBlock) fetchMeta() (details []*model.ObjectViewDetailsSet, object
445445
objectTypes, err = sb.objectStore.GetObjectTypes(uniqueObjTypes)
446446
if err != nil {
447447
log.With("objectID", sb.Id()).Errorf("error while fetching meta: get object types: %s", err)
448+
err = nil
448449
}
449450
go sb.metaListener(recordsCh)
450451
return

pkg/lib/localstore/objectstore/objects.go

+13-6
Original file line numberDiff line numberDiff line change
@@ -492,6 +492,8 @@ func (s *dsObjectStore) GetInboundLinksByID(id string) ([]string, error) {
492492
return findInboundLinks(txn, id)
493493
}
494494

495+
// GetDetails returns empty struct without errors in case details are not found
496+
// todo: get rid of this or change the name method!
495497
func (s *dsObjectStore) GetDetails(id string) (*model.ObjectDetails, error) {
496498
txn, err := s.ds.NewTransaction(true)
497499
if err != nil {
@@ -774,20 +776,25 @@ func (s *dsObjectStore) GetObjectType(url string) (*model.ObjectType, error) {
774776
if strings.HasPrefix(url, addr.BundledObjectTypeURLPrefix) {
775777
return bundle.GetTypeByUrl(url)
776778
}
777-
objectInfos, err := s.GetByIDs(url)
779+
780+
details, err := s.GetDetails(url)
778781
if err != nil {
779782
return nil, err
780783
}
781-
if len(objectInfos) == 0 {
782-
return nil, fmt.Errorf("object type not found in the index")
784+
785+
if pbtypes.IsStructEmpty(details.GetDetails()) {
786+
return nil, ErrObjectNotFound
787+
}
788+
789+
if pbtypes.GetBool(details.GetDetails(), bundle.RelationKeyIsDeleted.String()) {
790+
return nil, fmt.Errorf("type was removed")
783791
}
784-
details := objectInfos[0].Details
785792

786-
if pbtypes.GetString(details, bundle.RelationKeyType.String()) != bundle.TypeKeyObjectType.URL() {
793+
if pbtypes.GetString(details.Details, bundle.RelationKeyType.String()) != bundle.TypeKeyObjectType.URL() {
787794
return nil, fmt.Errorf("object %s is not an object type", url)
788795
}
789796

790-
return s.extractObjectTypeFromDetails(details, url), nil
797+
return s.extractObjectTypeFromDetails(details.Details, url), nil
791798
}
792799

793800
func (s *dsObjectStore) extractObjectTypeFromDetails(details *types.Struct, url string) *model.ObjectType {

util/pbtypes/pbtypes.go

+11
Original file line numberDiff line numberDiff line change
@@ -545,3 +545,14 @@ func ValidateValue(t *types.Value) error {
545545
}
546546
return nil
547547
}
548+
549+
func IsStructEmpty(s *types.Struct) bool {
550+
if s == nil {
551+
return true
552+
} else if s.GetFields() == nil {
553+
return true
554+
} else if len(s.GetFields()) == 0 {
555+
return true
556+
}
557+
return false
558+
}

0 commit comments

Comments
 (0)