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 · 5 comments
Open

Should we check nil pointer query in dataselect #9262

warjiang opened this issue Jul 20, 2024 · 5 comments
Labels
kind/feature Categorizes issue or PR as related to a new feature. lifecycle/rotten Denotes an issue or PR that has aged beyond stale and will be auto-closed.

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
@k8s-triage-robot
Copy link

The Kubernetes project currently lacks enough contributors to adequately respond to all issues.

This bot triages un-triaged issues according to the following rules:

  • After 90d of inactivity, lifecycle/stale is applied
  • After 30d of inactivity since lifecycle/stale was applied, lifecycle/rotten is applied
  • After 30d of inactivity since lifecycle/rotten was applied, the issue is closed

You can:

  • Mark this issue as fresh with /remove-lifecycle stale
  • Close this issue with /close
  • Offer to help out with Issue Triage

Please send feedback to sig-contributor-experience at kubernetes/community.

/lifecycle stale

@k8s-ci-robot k8s-ci-robot added the lifecycle/stale Denotes an issue or PR has remained open with no activity and has become stale. label Oct 18, 2024
@maciaszczykm
Copy link
Member

@warjiang are you willing to work on it?

@warjiang
Copy link
Author

@warjiang are you willing to work on it?

Yes, I think it should check the nil pointer, but no repsonse or no more discussion about it. Should I make contribution and ask for some review the changes?

@maciaszczykm
Copy link
Member

@warjiang Yes, that would be perfect.

@k8s-triage-robot
Copy link

The Kubernetes project currently lacks enough active contributors to adequately respond to all issues.

This bot triages un-triaged issues according to the following rules:

  • After 90d of inactivity, lifecycle/stale is applied
  • After 30d of inactivity since lifecycle/stale was applied, lifecycle/rotten is applied
  • After 30d of inactivity since lifecycle/rotten was applied, the issue is closed

You can:

  • Mark this issue as fresh with /remove-lifecycle rotten
  • Close this issue with /close
  • Offer to help out with Issue Triage

Please send feedback to sig-contributor-experience at kubernetes/community.

/lifecycle rotten

@k8s-ci-robot k8s-ci-robot added lifecycle/rotten Denotes an issue or PR that has aged beyond stale and will be auto-closed. and removed lifecycle/stale Denotes an issue or PR has remained open with no activity and has become stale. labels Nov 21, 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. lifecycle/rotten Denotes an issue or PR that has aged beyond stale and will be auto-closed.
Projects
None yet
Development

No branches or pull requests

4 participants