Skip to content

Conversation

@khanhtc1202
Copy link
Member

@khanhtc1202 khanhtc1202 commented Apr 8, 2022

What this PR does / why we need it:

Previously, for queries of kind

{
	Field:    "Kind",
	Operator: datastore.OperatorEqual,
	Value:    model.ApplicationKind_KUBERNETES,
}

the filter logic of filedb will return false even the model object has field Kind of the same value. That is caused by the unmarshaled model object only contains primitive types (to keep filedb layer generic, we only cast raw byte of models to map[string]interface{}, not it true type), and the operand value from queries is of its wrapped type (for instance model.ApplicationKind). As the result, comparing those two values will return (mismatched type model.ApplicationKind and float64) error. This PR provides logic to convert types which not a primitive type of filter.Value to primitive types, so the filter compare logic could work.

Which issue(s) this PR fixes:

Fixes #3494

Does this PR introduce a user-facing change?:

NONE

@pipecd-bot
Copy link
Collaborator

COVERAGE

Code coverage for golang is 35.62%. This pull request increases coverage by 0.06%.

File Function Base Head Diff
pkg/datastore/filedb/filter.go normalizeFieldValue -- 83.33% +83.33%
pkg/datastore/filedb/filter.go compare 76.67% 78.33% +1.67%
pkg/model/deployment.go GetNotCompletedDeploymentStatuses 0.00% 100.00% +100.00%
pkg/datastore/filedb/filter.go filter 71.43% 70.97% -0.46%

@pipecd-bot
Copy link
Collaborator

COVERAGE

Code coverage for golang is 35.62%. This pull request increases coverage by 0.06%.

File Function Base Head Diff
pkg/datastore/filedb/filter.go normalizeFieldValue -- 83.33% +83.33%
pkg/model/deployment.go GetNotCompletedDeploymentStatuses 0.00% 100.00% +100.00%
pkg/datastore/filedb/filter.go filter 71.43% 70.97% -0.46%
pkg/datastore/filedb/filter.go compare 76.67% 78.33% +1.67%

@nghialv
Copy link
Member

nghialv commented Apr 11, 2022

👍

/lgtm

Copy link
Member

@knanao knanao left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks good.
/approve

@pipecd-bot
Copy link
Collaborator

APPROVE

This pull request is APPROVED by knanao.

Approvers can cancel the approval by writing /approve cancel in a comment. Any additional commits also will change this pull request to be not-approved.

@pipecd-bot pipecd-bot merged commit d1899ea into master Apr 11, 2022
@pipecd-bot pipecd-bot deleted the handle-declared-type branch April 11, 2022 04:26
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

[FILEDB] Unable to filter correctly if the value passed through filter.Value is declared type

5 participants