Skip to content

[Form] Fix keep_as_list when data is not an array #60638

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

Open
wants to merge 1 commit into
base: 7.2
Choose a base branch
from

Conversation

MatTheCat
Copy link
Contributor

@MatTheCat MatTheCat commented Jun 2, 2025

Q A
Branch? 7.2
Bug fix? yes
New feature? no
Deprecations? no
Issues Fix part of #57430
License MIT

The CollectionType handles not only arrays but also ArrayAccess&Traversable. However when setting its keep_as_list option, array_values would then be called and crash.

To avoid this, this PR reindexes the data by getting its keys and unsetting them. This is because unsetting in a loop can produce counter-intuitive results; e.g. ArrayIterator would skip indexes.

Note that #57430 mentions another issue that would be fixed by #59910.

@MatTheCat MatTheCat requested review from xabbuh and yceruto as code owners June 2, 2025 15:04
@carsonbot carsonbot added this to the 7.2 milestone Jun 2, 2025
@MatTheCat MatTheCat force-pushed the keep_as_list-without-array branch from 945573e to 86b5597 Compare June 2, 2025 15:08
@stof
Copy link
Member

stof commented Jun 2, 2025

Speaking of ArrayIterator, it is a native candidate for ArrayAccess&Traversable so this PR uses it instead of Doctrine’s ArrayCollection which allows to drop the dependency to doctrine/collections.

keeping tests using doctrine/collections has the benefit of ensuring it works with doctrine/collections, which corresponds to a common use case in the ecosystem (not all ArrayAccess&Traversable might behave the same)

@MatTheCat
Copy link
Contributor Author

MatTheCat commented Jun 2, 2025

If we only want to test against Doctrine collections maybe the CollectionType should only accept them rather than ArrayAccess&Traversable?

@stof
Copy link
Member

stof commented Jun 2, 2025

@MatTheCat I did not say "only" in my message. But keeping a test using ArrayCollection brings value to our testsuite, even if it implies a dev dependency on doctrine/collections

@MatTheCat MatTheCat force-pushed the keep_as_list-without-array branch from 86b5597 to 643592f Compare June 2, 2025 15:43
@MatTheCat
Copy link
Contributor Author

Okay kept the existing test against ArrayCollection.

@MatTheCat MatTheCat force-pushed the keep_as_list-without-array branch from 4433af8 to 1f4dd71 Compare June 6, 2025 16:50
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

5 participants
pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy