dashboard icon indicating copy to clipboard operation
dashboard copied to clipboard

Should we check nil pointer query in dataselect

Open warjiang opened this issue 1 year ago • 4 comments

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

warjiang avatar Jul 20 '24 03:07 warjiang

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-triage-robot avatar Oct 18 '24 04:10 k8s-triage-robot

@warjiang are you willing to work on it?

maciaszczykm avatar Oct 22 '24 08:10 maciaszczykm

@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?

warjiang avatar Oct 22 '24 09:10 warjiang

@warjiang Yes, that would be perfect.

maciaszczykm avatar Oct 22 '24 12:10 maciaszczykm

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-triage-robot avatar Nov 21 '24 13:11 k8s-triage-robot

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

This bot triages 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:

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

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

/close not-planned

k8s-triage-robot avatar Dec 21 '24 14:12 k8s-triage-robot

@k8s-triage-robot: Closing this issue, marking it as "Not Planned".

In response to this:

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

This bot triages 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:

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

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

/close not-planned

Instructions for interacting with me using PR comments are available here. If you have questions or suggestions related to my behavior, please file an issue against the kubernetes-sigs/prow repository.

k8s-ci-robot avatar Dec 21 '24 14:12 k8s-ci-robot