Skip to content
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

Block.parent loss on serialization during snapshot creation #1797

Open
tdumalin opened this issue Feb 21, 2025 · 0 comments
Open

Block.parent loss on serialization during snapshot creation #1797

tdumalin opened this issue Feb 21, 2025 · 0 comments

Comments

@tdumalin
Copy link
Contributor

Environment

Sonata packages

show

$ composer show --latest 'sonata-project/*'
Color legend:                                                                       
- patch or minor release available - update recommended
- major release available - update possible
- up to date version

Direct dependencies required in composer.json:
sonata-project/admin-bundle              4.35.4 4.35.4 The missing Symfony Admin Generator
sonata-project/doctrine-orm-admin-bundle 4.18.0 4.18.0 Integrate Doctrine ORM into the SonataAdminBundle
sonata-project/media-bundle              4.15.0 4.15.0 Symfony SonataMediaBundle
sonata-project/page-bundle               4.8.0  4.8.0  This bundle provides a Site and Page management through container and block services

Transitive dependencies not required in composer.json:
sonata-project/block-bundle              5.1.2  5.1.2  Symfony SonataBlockBundle
sonata-project/doctrine-extensions       2.5.0  2.5.0  Doctrine2 behavioral extensions
sonata-project/exporter                  3.3.1  3.3.1  Lightweight Exporter library
sonata-project/form-extensions           2.4.1  2.4.1  Symfony form extensions
sonata-project/seo-bundle                3.8.0  3.8.0  Symfony SonataSeoBundle
sonata-project/twig-extensions           2.5.0  2.5.0  Sonata twig extensions

Symfony packages

show

$ composer show --latest 'symfony/*'
Color legend:                                                                       
- patch or minor release available - update recommended
- major release available - update possible
- up to date version

Direct dependencies required in composer.json:
symfony/asset                      7.2.0  7.2.0  Manages URL generation and versioning of web assets such as CSS stylesheets, JavaScript files and image ...
symfony/console                    7.2.1  7.2.1  Eases the creation of beautiful and testable command line interfaces
symfony/debug-bundle               7.2.0  7.2.0  Provides a tight integration of the Symfony VarDumper component and the ServerLogCommand from MonologBri...
symfony/dotenv                     7.2.0  7.2.0  Registers environment variables from a .env file
symfony/flex                       2.4.7  2.4.7  Composer plugin for Symfony
symfony/form                       7.2.3  7.2.3  Allows to easily create, process and reuse HTML forms
symfony/framework-bundle           7.2.3  7.2.3  Provides a tight integration between Symfony components and the Symfony full-stack framework
symfony/mailer                     7.2.3  7.2.3  Helps sending emails
symfony/maker-bundle               1.62.1 1.62.1 Symfony Maker helps you create empty commands, controllers, form classes, tests and more so you can forg...
symfony/monolog-bundle             3.10.0 3.10.0 Symfony MonologBundle
symfony/runtime                    7.2.3  7.2.3  Enables decoupling PHP applications from global state
symfony/security-csrf              7.2.3  7.2.3  Symfony Security Component - CSRF Library
symfony/stimulus-bundle            2.23.0 2.23.0 Integration with your Symfony app & Stimulus!
symfony/stopwatch                  7.2.2  7.2.2  Provides a way to profile code
symfony/twig-bundle                7.2.0  7.2.0  Provides a tight integration of Twig into the Symfony full-stack framework
symfony/ux-icons                   2.23.0 2.23.0 Renders local and remote SVG icons in your Twig templates.
symfony/ux-live-component          2.23.0 2.23.0 Live components for Symfony
symfony/ux-twig-component          2.23.0 2.23.0 Twig components for Symfony
symfony/web-profiler-bundle        7.2.3  7.2.3  Provides a development tool that gives detailed information about the execution of any request
symfony/webpack-encore-bundle      2.2.0  2.2.0  Integration of your Symfony app with Webpack Encore
symfony/yaml                       7.2.3  7.2.3  Loads and dumps YAML files

Transitive dependencies not required in composer.json:
symfony/cache                      7.2.3  7.2.3  Provides extended PSR-6, PSR-16 (and tags) implementations
symfony/cache-contracts            3.5.1  3.5.1  Generic abstractions related to caching
symfony/clock                      7.2.0  7.2.0  Decouples applications from the system clock
symfony/config                     7.2.3  7.2.3  Helps you find, load, combine, autofill and validate configuration values of any kind
symfony/dependency-injection       7.2.3  7.2.3  Allows you to standardize and centralize the way objects are constructed in your application
symfony/deprecation-contracts      3.5.1  3.5.1  A generic function and convention to trigger deprecation notices
symfony/doctrine-bridge            7.2.3  7.2.3  Provides integration for Doctrine with various Symfony components
symfony/error-handler              7.2.3  7.2.3  Provides tools to manage errors and ease debugging PHP code
symfony/event-dispatcher           7.2.0  7.2.0  Provides tools that allow your application components to communicate with each other by dispatching even...
symfony/event-dispatcher-contracts 3.5.1  3.5.1  Generic abstractions related to dispatching event
symfony/expression-language        7.2.0  7.2.0  Provides an engine that can compile and evaluate expressions
symfony/filesystem                 7.2.0  7.2.0  Provides basic utilities for the filesystem
symfony/finder                     7.2.2  7.2.2  Finds files and directories via an intuitive fluent interface
symfony/http-client                7.2.3  7.2.3  Provides powerful methods to fetch HTTP resources synchronously or asynchronously
symfony/http-client-contracts      3.5.2  3.5.2  Generic abstractions related to HTTP clients
symfony/http-foundation            7.2.3  7.2.3  Defines an object-oriented layer for the HTTP specification
symfony/http-kernel                7.2.3  7.2.3  Provides a structured process for converting a Request into a Response
symfony/intl                       7.2.0  7.2.0  Provides access to the localization data of the ICU library
symfony/mime                       7.2.3  7.2.3  Allows manipulating MIME messages
symfony/monolog-bridge             7.2.0  7.2.0  Provides integration for Monolog with various Symfony components
symfony/options-resolver           7.2.0  7.2.0  Provides an improved replacement for the array_replace PHP function
symfony/password-hasher            7.2.0  7.2.0  Provides password hashing utilities
symfony/polyfill-intl-grapheme     1.31.0 1.31.0 Symfony polyfill for intl's grapheme_* functions
symfony/polyfill-intl-icu          1.31.0 1.31.0 Symfony polyfill for intl's ICU-related data and classes
symfony/polyfill-intl-idn          1.31.0 1.31.0 Symfony polyfill for intl's idn_to_ascii and idn_to_utf8 functions
symfony/polyfill-intl-normalizer   1.31.0 1.31.0 Symfony polyfill for intl's Normalizer class and related functions
symfony/polyfill-mbstring          1.31.0 1.31.0 Symfony polyfill for the Mbstring extension
symfony/polyfill-php83             1.31.0 1.31.0 Symfony polyfill backporting some PHP 8.3+ features to lower PHP versions
symfony/process                    7.2.0  7.2.0  Executes commands in sub-processes
symfony/property-access            7.2.3  7.2.3  Provides functions to read and write from/to an object or array using a simple string notation
symfony/property-info              7.2.3  7.2.3  Extracts information about PHP class' properties using metadata of popular sources
symfony/routing                    7.2.3  7.2.3  Maps an HTTP request to a set of configuration variables
symfony/security-acl               3.3.4  3.3.4  Symfony Security Component - ACL (Access Control List)
symfony/security-bundle            7.2.3  7.2.3  Provides a tight integration of the Security component into the Symfony full-stack framework
symfony/security-core              7.2.3  7.2.3  Symfony Security Component - Core Library
symfony/security-http              7.2.3  7.2.3  Symfony Security Component - HTTP Integration
symfony/serializer                 7.2.3  7.2.3  Handles serializing and deserializing data structures, including object graphs, into array structures or...
symfony/service-contracts          3.5.1  3.5.1  Generic abstractions related to writing services
symfony/string                     7.2.0  7.2.0  Provides an object-oriented API to strings and deals with bytes, UTF-8 code points and grapheme clusters...
symfony/translation                7.2.2  7.2.2  Provides tools to internationalize your application
symfony/translation-contracts      3.5.1  3.5.1  Generic abstractions related to translation
symfony/twig-bridge                7.2.2  7.2.2  Provides integration for Twig with various Symfony components
symfony/type-info                  7.2.2  7.2.2  Extracts PHP types information.
symfony/validator                  7.2.3  7.2.3  Provides tools to validate values
symfony/var-dumper                 7.2.3  7.2.3  Provides mechanisms for walking through any arbitrary PHP variable
symfony/var-exporter               7.2.0  7.2.0  Allows exporting any serializable PHP data structure to plain PHP code

PHP version

$ php -v
PHP 8.3.16 (cli) (built: Jan 17 2025 01:31:09) (ZTS)
Copyright (c) The PHP Group
Zend Engine v4.3.16, Copyright (c) Zend Technologies
    with Zend OPcache v8.3.16, Copyright (c), by Zend Technologies
    with Xdebug v3.4.1, Copyright (c) 2002-2025, by Derick Rethans

Subject

The Sonata\PageBundle\Entity\Transformer now use serializer to create a snapshot, all objects are ignored and so the block page is not serialized:
Ex:

    0 => array:8 [▼
      "id" => 39
      "blocks" => []
      "settings" => array:1 [▼
        "template" => "block/breadcrumb.html.twig"
      ]
      "enabled" => true
      "position" => 0
      "created_at" => "1740055293"
      "updated_at" => "1740055309"
      "type" => "App\Block\BreadcrumbBlock"
     // <---- no page key defined
    ]

Then when the block is normalized in the BlockContextInterface the page are null

<?php

namespace App\Block;
// ....

class BreadcrumbBlock extends AbstractBlockService implements EditableBlockService
{
   //....

    public function execute(BlockContextInterface $blockContext, ?Response $response = null): Response
    {
           // when logged as a page editor everything works normally because it use the proxy system, but as anonymous user this throw an error ""
           $pageId = $blockContext->getBlock()->getPage()->getId();
    }
}

Minimal repository with the bug

Steps to reproduce

Try to access blockContext.block.page as an anonymous user

Expected results

the block page

Actual results

"Call to a member function getId() on null"

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

1 participant