-
-
Notifications
You must be signed in to change notification settings - Fork 9.6k
[PropertyAccess] Fails with poorly indexed arrays #10099
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
Comments
This is not necessarily a poorly indexed array, the key could be representing an id, and thus be perfectly legitimate. This main source of the problem seems to be that However, Plus, this whole concept seems rather inefficient. It means that if I ask for index 1000, it will create a thousand empty items just to later call the last item and trash the rest. |
You're right, a poorly indexed array isn't the best way to describe it, I was strapped for time and couldn't think of a way of describing them concisely (I guess non-consecutive would be better). I agree it seems like odd behaviour, and yes because we're using Doctrine it is actually performing this on a PersistentCollection and hence it is actually creating these empty indexes. I don't think it wouldn't even get to index 1,000 - it seems to limit the amount of properties it will read based on the amount of properties in the array. So it would iterate once, try and access index 0, fail and create that index, and then stop. When I get time I will put together some tests to try this theory. |
This is not true. PropertyAccessor only accessed/creates array indexes that are explicitly requested. |
Btw, seems related to #7828 |
Lets say I'm submitting a form, built from a collection, with just the following form information:
form[main][1][test1]: 10
form[main][1][test2]: test
The PropertyAccess bundle will try and access this property, but detects form[main][1] as a numeric index. Then when calling PropertyAccessor::getValue, it tries to iterate through all the properties of 'main' as if it was a zero indexed array. This means it will try and access form[main][0], even though it does not exist. PropertyAccessory::readPropertiesUntil with then create form[main][0] which will fail any NotBlank validations later on - even though it was never submitted in the original form.
This might sound like it's easily fixable by just ensuring that the form always submits properly indexed arrays. However this isn't the case with most Javascript solutions used for collections - they can easily create broken indexes when removing collection items in the middle of other collection items.
If none of this makes sense, please let me know and I can explain with some proof of concept code.
The text was updated successfully, but these errors were encountered: