Skip to content

Commit

Permalink
Fix isNil WF expression function
Browse files Browse the repository at this point in the history
  • Loading branch information
KinyaElGrande committed Nov 28, 2024
1 parent b47ec87 commit 78b644a
Show file tree
Hide file tree
Showing 13 changed files with 91 additions and 45 deletions.
5 changes: 0 additions & 5 deletions server/compose/automation/expr_types.go
Original file line number Diff line number Diff line change
Expand Up @@ -293,11 +293,6 @@ func composeRecordValuesGValSelector(res *types.Record, k string) (interface{},
return false, nil
}

// return nil time.Time for date and time fields
if field != nil && (field.IsDateOnly() || field.IsDateTime() || field.IsTimeOnly()) {
return expr.NewDateTime(nil)
}

return nil, nil

case len(vv) == 1 && !multiValueField:
Expand Down
12 changes: 12 additions & 0 deletions server/compose/automation/expr_types_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,8 @@ func TestRecordFieldValuesAccess(t *testing.T) {
&types.ModuleField{Name: "n1", Multi: false, Kind: "Number"},
&types.ModuleField{Name: "n2", Multi: false, Kind: "Number"},
&types.ModuleField{Name: "n3", Multi: false, Kind: "Number"},
&types.ModuleField{Name: "d1", Multi: false, Kind: "DateTime"},
&types.ModuleField{Name: "d2", Multi: false, Kind: "DateTime"},
&types.ModuleField{Name: "ref1", Multi: false, Kind: "Record"},
&types.ModuleField{Name: "ref2", Multi: false, Kind: "Record"},
}}
Expand All @@ -56,6 +58,8 @@ func TestRecordFieldValuesAccess(t *testing.T) {
&types.RecordValue{Name: "n2", Value: "0", Place: 0},
&types.RecordValue{Name: "n3", Value: "2", Place: 0},
&types.RecordValue{Name: "ref2", Value: "", Ref: 2, Place: 0},
&types.RecordValue{Name: "d1", Value: "", Place: 0},
&types.RecordValue{Name: "d2", Value: "1999-09-09 09:09:09.000000009 +0000 UTC", Place: 0},
}
raw = &types.Record{Values: rawValues}

Expand Down Expand Up @@ -237,6 +241,14 @@ func TestRecordFieldValuesAccess(t *testing.T) {
{true, `rec.values.ref1 != 2`},
{true, `rec.values.ref2 == 2`},
{true, `rec.values.ref2 == "2"`},

{true, `isNil(nil)`},
{true, `isNil(rec.values.d1)`},
{true, `rec.values.n3 ? true : false`},
{false, `rec.values.d1 ? true : false`},
{true, `rec.values.d2 ? true : false`},
{true, `rec.values.d1 ? true : false || true `},
{false, `rec.values.d1 ? true : false && true `},
}

for _, tc := range tcc {
Expand Down
4 changes: 2 additions & 2 deletions server/go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -73,6 +73,7 @@ require (
go.uber.org/zap v1.21.0
golang.org/x/crypto v0.19.0
golang.org/x/image v0.15.0
golang.org/x/net v0.21.0
golang.org/x/oauth2 v0.16.0
golang.org/x/text v0.14.0
google.golang.org/grpc v1.61.1
Expand Down Expand Up @@ -135,7 +136,6 @@ require (
github.com/spf13/pflag v1.0.5 // indirect
github.com/valyala/fasthttp v1.35.0 // indirect
go.uber.org/multierr v1.7.0 // indirect
golang.org/x/net v0.21.0 // indirect
golang.org/x/sys v0.17.0 // indirect
golang.org/x/term v0.17.0 // indirect
google.golang.org/appengine v1.6.8 // indirect
Expand All @@ -147,4 +147,4 @@ require (

replace github.com/doug-martin/goqu/v9 => github.com/cortezaproject/goqu/v9 v9.18.4

replace github.com/PaesslerAG/gval => github.com/cortezaproject/gval v1.2.2
replace github.com/PaesslerAG/gval => github.com/cortezaproject/gval v1.2.4
4 changes: 2 additions & 2 deletions server/go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -109,8 +109,8 @@ github.com/cncf/udpa/go v0.0.0-20200629203442-efcf912fb354/go.mod h1:WmhPx2Nbnht
github.com/cncf/udpa/go v0.0.0-20201120205902-5459f2c99403/go.mod h1:WmhPx2Nbnhtbo57+VJT5O0JRkEi1Wbu0z5j0R8u5Hbk=
github.com/cortezaproject/goqu/v9 v9.18.4 h1:HV7Ocf6xYHIqU4buxYkg3Ght/en93Yr1m71KPhJXW0Y=
github.com/cortezaproject/goqu/v9 v9.18.4/go.mod h1:nf0Wc2/hV3gYK9LiyqIrzBEVGlI8qW3GuDCEobC4wBQ=
github.com/cortezaproject/gval v1.2.2 h1:zSMy5xtFpe4YSG9+zW5DF/k2YlqXOOJHDc6y6kCl8ro=
github.com/cortezaproject/gval v1.2.2/go.mod h1:XRFLwvmkTEdYziLdaCeCa5ImcGVrfQbeNUbVR+C6xac=
github.com/cortezaproject/gval v1.2.4 h1:EtARN6gIAMM30ljQ1wSSwL3ZpJwrM9wCX67O2tT+fzo=
github.com/cortezaproject/gval v1.2.4/go.mod h1:XRFLwvmkTEdYziLdaCeCa5ImcGVrfQbeNUbVR+C6xac=
github.com/cpuguy83/go-md2man/v2 v2.0.1/go.mod h1:tgQtvFlXSQOSOSIRvRPT7W67SCa46tRHOmNcaadrF8o=
github.com/creack/pty v1.1.9/go.mod h1:oKZEueFk5CKHvIhNR5MUki03XCEU+Q6VDXinZuGJ33E=
github.com/crewjam/httperr v0.2.0 h1:b2BfXR8U3AlIHwNeFFvZ+BV1LFvKLlzMjzaTnZMybNo=
Expand Down
3 changes: 1 addition & 2 deletions server/pkg/expr/func_generic.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,10 +2,9 @@ package expr

import (
"fmt"
"reflect"

"github.com/PaesslerAG/gval"
"github.com/cortezaproject/corteza/server/pkg/gvalfnc"
"reflect"
)

type (
Expand Down
45 changes: 30 additions & 15 deletions server/vendor/github.com/PaesslerAG/gval/evaluable.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

8 changes: 5 additions & 3 deletions server/vendor/github.com/PaesslerAG/gval/functions.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

25 changes: 17 additions & 8 deletions server/vendor/github.com/PaesslerAG/gval/gval.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion server/vendor/github.com/PaesslerAG/gval/language.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

14 changes: 14 additions & 0 deletions server/vendor/github.com/PaesslerAG/gval/operator.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

4 changes: 2 additions & 2 deletions server/vendor/github.com/PaesslerAG/gval/parse.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

6 changes: 3 additions & 3 deletions server/vendor/github.com/PaesslerAG/gval/parser.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Loading

0 comments on commit 78b644a

Please sign in to comment.