Skip to content
This repository has been archived by the owner on Jan 8, 2020. It is now read-only.

CollectionInputFilter->getCount() gives wrong count on consecutive setData() calls #6160

Closed
wants to merge 1 commit into from
Closed

CollectionInputFilter->getCount() gives wrong count on consecutive setData() calls #6160

wants to merge 1 commit into from

Conversation

halaxa
Copy link
Contributor

@halaxa halaxa commented Apr 18, 2014

If no count is explicitly set using setCount() on CollectionInputFilter, evaluated count($this->data) is saved and then served across different data set by setData() even if it it's valid no more. This patch makes it not to save temporary value across different data.

@danizord
Copy link
Contributor

Ping @fabiocarneiro

@halaxa
Copy link
Contributor Author

halaxa commented Apr 25, 2014

It therefore fails validating consecutive data sets of different count as isValid() calls getCount(). So it's an unpleasant bug. Shall i make an issue?

@Ocramius
Copy link
Member

@halaxa who is using setCount? Can the property be completely removed?

@Ocramius Ocramius added this to the 2.3.2 milestone Apr 29, 2014
@halaxa
Copy link
Contributor Author

halaxa commented Apr 29, 2014

I'm not:) I understand that setCount() may be used to add a count check on the given data. It is not valid if actual count is lower than set count. There is also config key for it. But to me it seems redundant as one can easily use some kind of more variable count validator in validation chain if needed although I don't see any present right now.

@Ocramius
Copy link
Member

@halaxa can you find its usages and eventually mark it as @deprecated? It should just do nothing.

@Ocramius Ocramius modified the milestones: 2.4.0, 2.3.2 Apr 29, 2014
@Ocramius
Copy link
Member

Also, marking this as a BC break and delaying to 2.4.0

@halaxa
Copy link
Contributor Author

halaxa commented Apr 29, 2014

What if we split it up and use this patch now and the other removing count property later in 2.4?

@halaxa
Copy link
Contributor Author

halaxa commented Apr 29, 2014

Our project kind of needs this to be just fixed, nothing more:)

@danizord
Copy link
Contributor

I'm not sure why the count property is not being used anymore, that's really needed:

$inputFilter = new \Zend\InputFilter\InputFilter();
$inputFilter->add([
    'name' => 'collection',
    'type' => 'Zend\InputFilter\CollectionInputFilter',
    'options' => [
        // Requires 3 elements
        'count' => 3,
    ],
]);
// Fill with 2 elements
$inputFilter->setData([
    'collection' => [
        ['name' => 'item1'],
        ['name' => 'item2']
    ]
]);
$this->assertFalse($inputFilter->isValid());

@Ocramius
Copy link
Member

@danizord is it a documented behavior? Looks kinda silly to me.

@halaxa you could rely on either your internal branch or dev-develop until this is merged into master.

@fabiocarneiro
Copy link
Contributor

#edit Sorry, this PR is right and should be merged. It does not break bc.

@Ocramius We can't remove the property because it will still be used by the factory. It will only be used if you set the required count in the spec.

@danizord
Copy link
Contributor

@Ocramius Yes, that behavior is covered by testDataLessThanCountIsInvalid().

@halaxa
Copy link
Contributor Author

halaxa commented Apr 29, 2014

What about just fixing current behaviour and create an issue about this?

@weierophinney weierophinney modified the milestones: 2.4.0, 2.3.2 Aug 6, 2014
@Ocramius Ocramius removed the BC Break label Aug 6, 2014
@Ocramius Ocramius self-assigned this Aug 6, 2014
@Ocramius Ocramius closed this in e50ddd2 Aug 6, 2014
Ocramius added a commit that referenced this pull request Aug 6, 2014
@Ocramius
Copy link
Member

Ocramius commented Aug 6, 2014

Merged, thanks!

gianarb pushed a commit to zendframework/zend-inputfilter that referenced this pull request May 15, 2015
gianarb pushed a commit to zendframework/zend-inputfilter that referenced this pull request May 15, 2015
gianarb pushed a commit to zendframework/zend-inputfilter that referenced this pull request May 15, 2015
…t-filter-count-fix-for-multiple-setdata-calls' into develop

Forward port zendframework/zendframework#6160
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

5 participants