Thanks to visit codestin.com
Credit goes to github.com

Skip to content
Permalink

Comparing changes

Choose two branches to see what’s changed or to start a new pull request. If you need to, you can also or learn more about diff comparisons.

Open a pull request

Create a new pull request by comparing changes across two branches. If you need to, you can also . Learn more about diff comparisons here.
base repository: symfony/serializer
Failed to load repositories. Confirm that selected base ref is valid, then try again.
Loading
base: v7.2.6
Choose a base ref
...
head repository: symfony/serializer
Failed to load repositories. Confirm that selected head ref is valid, then try again.
Loading
compare: v7.2.7
Choose a head ref
  • 3 commits
  • 2 files changed
  • 3 contributors

Commits on May 12, 2025

  1. Fix: prevent "Cannot traverse an already closed generator" error by m…

    …aterializing Traversable input
    santysisi authored and fabpot committed May 12, 2025
    Configuration menu
    Copy the full SHA
    72bf83d View commit details
    Browse the repository at this point in the history
  2. bug #60260 [Serializer] Prevent `Cannot traverse an already closed ge…

    …nerator` error by materializing Traversable input (santysisi)
    
    This PR was merged into the 6.4 branch.
    
    Discussion
    ----------
    
    [Serializer] Prevent `Cannot traverse an already closed generator` error by materializing Traversable input
    
    | Q             | A
    | ------------- | ---
    | Branch?       | 6.4
    | Bug fix?      | yes
    | New feature?  | no
    | Deprecations? | no
    | Issues        | Fix #60141
    | License       | MIT
    
    ### ✅ Pull Request description:
    This PR addresses the issue reported in the linked ticket, specifically the error:
    `Cannot traverse an already closed generator`
    
    The fix involves converting `Traversable` input into an array using `iterator_to_array($data)`, in order to allow multiple traversals of generator-based inputs.
    
    At first glance, it might seem that this approach significantly increases memory usage, since all generator values are stored in memory. However, this is not the case. In the current logic, the following [loop](https://github.com/symfony/symfony/blob/6.4/src/Symfony/Component/Serializer/Encoder/CsvEncoder.php#L82-L86) already forces all values from the generator into memory:
    ```php
    foreach ($data as &$value) {
        $flattened = [];
        $this->flatten($value, $flattened, $keySeparator, '', $escapeFormulas);
        $value = $flattened;
    }
    ```
    Therefore, materializing the generator with `iterator_to_array() `does not increase peak memory usage in any meaningful way.
    As an example, here's the comparison of peak memory usage (measured with [memory_get_peak_usage](https://www.php.net/manual/en/function.memory-get-peak-usage.php)) when processing an array of 1 million integers:
    * **With the fix**: 90,044,272 bytes
    * **Without the fix**: 89,936,680 bytes
    
    The difference is negligible, confirming that the fix does not introduce a meaningful performance cost in terms of memory.
    
    Commits
    -------
    
    c7206a9 Fix: prevent "Cannot traverse an already closed generator" error by materializing Traversable input
    fabpot committed May 12, 2025
    Configuration menu
    Copy the full SHA
    b836df9 View commit details
    Browse the repository at this point in the history
  3. Merge branch '6.4' into 7.2

    * 6.4:
      Fix: prevent "Cannot traverse an already closed generator" error by materializing Traversable input
      [HttpFoundation] Fix: Encode path in X-Accel-Redirect header
    alexandre-daubois committed May 12, 2025
    Configuration menu
    Copy the full SHA
    33734cd View commit details
    Browse the repository at this point in the history
Loading