Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Should we check nil pointer query in dataselect #9262

Open
warjiang opened this issue Jul 20, 2024 · 0 comments
Open

Should we check nil pointer query in dataselect #9262

warjiang opened this issue Jul 20, 2024 · 0 comments
Labels
kind/feature Categorizes issue or PR as related to a new feature.

Comments

@warjiang
Copy link

warjiang commented Jul 20, 2024

What would you like to be added?

The dataselect is well designed to filter、sort、paginate datacells. I want to reuse the dataselect module in my project. But I metioned that FilterQuerySortQueryPaginationQuery may be nil and cause panic error, for example

// Filter the data inside as instructed by DataSelectQuery and returns itself to allow method chaining.
func (self *DataSelector) Filter() *DataSelector {
	filteredList := []DataCell{}

	for _, c := range self.GenericDataList {
		matches := true
		for _, filterBy := range self.DataSelectQuery.FilterQuery.FilterByList {
			v := c.GetProperty(filterBy.Property)
			if v == nil || !v.Contains(filterBy.Value) {
				matches = false
				break
			}
		}
		if matches {
			filteredList = append(filteredList, c)
		}
	}

	self.GenericDataList = filteredList
	return self
}

when we iterate self.DataSelectQuery.FilterQuery.FilterByList, if the FilterQuery is nil, it will panic.

The use-case of my code is following:

selectableData := dataselect.DataSelector{
    GenericDataList: ToCells(listResult.Items),
    DataSelectQuery: &dataselect.DataSelectQuery{
	//FilterQuery:     nil,
	//SortQuery:       nil,
	//PaginationQuery: nil,
	//FilterQuery:     dataselect.NewFilterQuery([]string{"name", "111"}),
	SortQuery: dataselect.NewSortQuery([]string{"a", "name"}),
	//PaginationQuery: dataselect.NewPaginationQuery(10, 2),
    },
}
selectableData.Filter().Sort().Paginate()

Apart from QueryFilter, the DataSelectQuery should also be checked to avoid nil pointer error.

Why is this needed?

For more robust, when the dataselect pkg is resued by other project.

Tasks

No tasks being tracked yet.
@warjiang warjiang added the kind/feature Categorizes issue or PR as related to a new feature. label Jul 20, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
kind/feature Categorizes issue or PR as related to a new feature.
Projects
None yet
Development

No branches or pull requests

1 participant