Skip to content

Commit d380979

Browse files
authored
Merge pull request #33 from linuxfoundation/andrest50/parent-ref
[LFXV2-923] Skip empty string values when extracting parent refs
2 parents ace4782 + e592101 commit d380979

File tree

3 files changed

+53
-2
lines changed

3 files changed

+53
-2
lines changed

charts/lfx-v2-indexer-service/Chart.yaml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,5 +6,5 @@ apiVersion: v2
66
name: lfx-v2-indexer-service
77
description: LFX Platform V2 Indexer Service chart
88
type: application
9-
version: 0.4.11
9+
version: 0.4.12
1010
appVersion: "latest"

internal/enrichers/default_enricher.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -304,7 +304,7 @@ func defaultSetParentReferences(body *contracts.TransactionBody, data map[string
304304

305305
parentRefFunc := func(pattern *regexp.Regexp) {
306306
for key, value := range data {
307-
if pattern.MatchString(key) && key != "parent_uid" && key != "parentID" {
307+
if pattern.MatchString(key) && key != "parent_uid" && key != "parentID" && value != nil && value != "" {
308308
// remove the suffix from the key
309309
match := pattern.FindStringSubmatch(key)
310310
if len(match) > 1 {

internal/enrichers/default_enricher_test.go

Lines changed: 51 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -663,6 +663,57 @@ func TestDefaultSetParentReferences(t *testing.T) {
663663
"project:false",
664664
},
665665
},
666+
{
667+
name: "empty string values are skipped",
668+
data: map[string]any{
669+
"uid": "test-123",
670+
"project_uid": "", // empty string should be skipped
671+
"committee_uid": "comm-456", // valid value
672+
"MeetingID": "", // empty string should be skipped
673+
},
674+
objectType: "event",
675+
expectedParents: []string{
676+
"committee:comm-456", // Only non-empty value should be included
677+
},
678+
},
679+
{
680+
name: "all empty string values result in no parent refs",
681+
data: map[string]any{
682+
"uid": "test-123",
683+
"project_uid": "",
684+
"committee_uid": "",
685+
"MeetingID": "",
686+
},
687+
objectType: "event",
688+
expectedParents: nil,
689+
},
690+
{
691+
name: "nil values are skipped",
692+
data: map[string]any{
693+
"uid": "test-123",
694+
"project_uid": nil, // nil value should be skipped
695+
"committee_uid": "comm-789", // valid value
696+
"meeting_uid": nil, // nil value should be skipped
697+
},
698+
objectType: "event",
699+
expectedParents: []string{
700+
"committee:comm-789", // Only non-nil value should be included
701+
},
702+
},
703+
{
704+
name: "mixed nil, empty string, and valid values",
705+
data: map[string]any{
706+
"uid": "test-123",
707+
"project_uid": nil, // nil - should be skipped
708+
"committee_uid": "", // empty string - should be skipped
709+
"meeting_uid": "meet-456", // valid value
710+
"ProjectID": nil, // nil - should be skipped
711+
},
712+
objectType: "event",
713+
expectedParents: []string{
714+
"meeting:meet-456", // Only valid value should be included
715+
},
716+
},
666717
}
667718

668719
for _, tt := range tests {

0 commit comments

Comments
 (0)