Skip to content

Commit 02f1b9b

Browse files
committed
Fix issue with DB ID not found in generator.
In the case there is a relation in the projection, but the related assets are not in the projection, the assets are not pushed into the registry leading to missing IDs when searching into it. In that case we can simply return id -1 because the relation won't be displayed anyway as we are missing one or both vertices.
1 parent 72709fc commit 02f1b9b

File tree

2 files changed

+15
-3
lines changed

2 files changed

+15
-3
lines changed

internal/database/id_generator.go

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,15 @@
11
package database
22

33
import (
4+
"errors"
45
"fmt"
56

67
"github.com/clems4ever/go-graphkb/internal/knowledge"
78
)
89

10+
// ErrInexistentDBID represent an error thrown when a DB ID has not been pushed into th registry
11+
var ErrInexistentDBID = errors.New("DB ID does not exist")
12+
913
// AssetTemporaryIDGenerator is a kind of cache associating IDs to assets so that pivot points are joined by those IDs
1014
type AssetTemporaryIDGenerator struct {
1115
// map the DB ID with a temporarily generated ID.
@@ -55,7 +59,7 @@ func (atig *AssetTemporaryIDGenerator) Push(asset knowledge.Asset, DBID int) (in
5559
func (atig *AssetTemporaryIDGenerator) Get(DBID int) (int, error) {
5660
id, ok := atig.DBIDToTemporaryID[DBID]
5761
if !ok {
58-
return 0, fmt.Errorf("DB ID %d does not exist in generator", DBID)
62+
return 0, ErrInexistentDBID
5963
}
6064
return id, nil
6165
}

internal/database/mariadb.go

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -658,12 +658,20 @@ func (mc *MariaDBCursor) Read(ctx context.Context, doc interface{}) error {
658658

659659
tmpIDFrom, err := mc.temporaryIDGenerator.Get(r.From)
660660
if err != nil {
661-
return fmt.Errorf("Unable to retrieve the temporary ID for DB ID %d (from): %v", r.From, err)
661+
if err == ErrInexistentDBID {
662+
tmpIDFrom = -1
663+
} else {
664+
return fmt.Errorf("Unable to retrieve the temporary ID for DB ID %d (from): %v", r.From, err)
665+
}
662666
}
663667

664668
tmpIDTo, err := mc.temporaryIDGenerator.Get(r.To)
665669
if err != nil {
666-
return fmt.Errorf("Unable to retrieve the temporary ID for DB ID %d (to): %v", r.To, err)
670+
if err == ErrInexistentDBID {
671+
tmpIDFrom = -1
672+
} else {
673+
return fmt.Errorf("Unable to retrieve the temporary ID for DB ID %d (to): %v", r.To, err)
674+
}
667675
}
668676

669677
output[i] = knowledge.RelationWithID{

0 commit comments

Comments
 (0)