sonata-project / SonataPageBundle

This bundle provides a Site and Page management through container and block services
https://docs.sonata-project.org/projects/SonataPageBundle
MIT License
216 stars 209 forks source link

Undefined property SonataPageBlock::$lazyObjectState #1747

Closed mesiarm closed 4 months ago

mesiarm commented 8 months ago

When I set enable_lazy_ghost_objects to true in doctrine.yaml (not setting true is deprecated) I got error after I updated sonata Block and wanted to create new Snapshot of page: User Notice: Undefined property: Proxies__CG__\App\Entity\SonataPageBlock::$lazyObjectState in ....\sonata\private\vendor\symfony\property-access\PropertyAccessor.php on line 488

VincentLanglet commented 8 months ago

Hi, when opening an issue, it always useful to fill correctly the template.

Sonata packages

show

``` $ composer show --latest 'sonata-project/*' # Put the result here. ```

Symfony packages

show

``` $ composer show --latest 'symfony/*' # Put the result here. ```

Also,

mesiarm commented 8 months ago
Sonata packages ``` sonata-project/admin-bundle 4.29.0 4.29.2 The missing Symfony Admin Generator sonata-project/block-bundle 5.1.0 5.1.0 Symfony SonataBlockBundle sonata-project/doctrine-extensions 2.3.0 2.3.0 Doctrine2 behavioral extensions sonata-project/doctrine-orm-admin-bundle 4.15.0 4.15.0 Integrate Doctrine ORM into the SonataAdminBundle sonata-project/exporter 3.3.0 3.3.0 Lightweight Exporter library sonata-project/form-extensions 2.3.0 2.3.0 Symfony form extensions sonata-project/formatter-bundle 5.3.0 5.3.0 Symfony SonataFormatterBundle sonata-project/intl-bundle 3.2.0 3.2.0 Symfony SonataIntlBundle sonata-project/media-bundle 4.11.0 4.11.0 Symfony SonataMediaBundle sonata-project/page-bundle 4.7.1 4.7.1 This bundle provides a Site and Page management through container and block services sonata-project/seo-bundle 3.8.0 3.8.0 Symfony SonataSeoBundle sonata-project/translation-bundle 3.3.0 3.3.0 SonataTranslationBundle sonata-project/twig-extensions 2.4.0 2.4.0 Sonata twig extensions sonata-project/user-bundle 5.10.0 5.10.0 Symfony SonataUserBundle ```
Symfony packages ``` symfony/asset v5.4.31 v6.4.0 Manages URL generation and versioning of web assets such as CSS stylesheets, JavaScript files and image files symfony/browser-kit v5.4.31 v6.4.0 Simulates the behavior of a web browser, allowing you to make requests, click on links and submit forms programmatically symfony/cache v5.4.34 v6.4.2 Provides extended PSR-6, PSR-16 (and tags) implementations symfony/cache-contracts v2.5.2 v3.4.0 Generic abstractions related to caching symfony/config v5.4.31 v6.4.0 Helps you find, load, combine, autofill and validate configuration values of any kind symfony/console v5.4.34 v6.4.2 Eases the creation of beautiful and testable command line interfaces symfony/css-selector v5.4.26 v6.4.0 Converts CSS selectors to XPath expressions symfony/debug-bundle v5.4.26 v6.4.0 Provides a tight integration of the Symfony VarDumper component and the ServerLogCommand from MonologBridge into the Symfony full-stack framework symfony/dependency-injection v5.4.34 v6.4.2 Allows you to standardize and centralize the way objects are constructed in your application symfony/deprecation-contracts v3.4.0 v3.4.0 A generic function and convention to trigger deprecation notices symfony/doctrine-bridge v5.4.34 v6.4.2 Provides integration for Doctrine with various Symfony components symfony/dom-crawler v5.4.32 v6.4.0 Eases DOM navigation for HTML and XML documents symfony/dotenv v5.4.34 v6.4.2 Registers environment variables from a .env file symfony/error-handler v5.4.29 v6.4.0 Provides tools to manage errors and ease debugging PHP code symfony/event-dispatcher v5.4.34 v6.4.2 Provides tools that allow your application components to communicate with each other by dispatching events and listening to them symfony/event-dispatcher-contracts v3.4.0 v3.4.0 Generic abstractions related to dispatching event symfony/expression-language v5.4.21 v6.4.2 Provides an engine that can compile and evaluate expressions symfony/filesystem v5.4.25 v6.4.0 Provides basic utilities for the filesystem symfony/finder v5.4.27 v6.4.0 Finds files and directories via an intuitive fluent interface symfony/flex v2.4.3 v2.4.3 Composer plugin for Symfony symfony/form v5.4.33 v6.4.1 Allows to easily create, process and reuse HTML forms symfony/framework-bundle v5.4.34 v6.4.2 Provides a tight integration between Symfony components and the Symfony full-stack framework symfony/http-client v5.4.34 v6.4.2 Provides powerful methods to fetch HTTP resources synchronously or asynchronously symfony/http-client-contracts v2.5.2 v3.4.0 Generic abstractions related to HTTP clients symfony/http-foundation v5.4.34 v6.4.2 Defines an object-oriented layer for the HTTP specification symfony/http-kernel v5.4.34 v6.4.2 Provides a structured process for converting a Request into a Response symfony/intl v5.4.30 v6.4.2 Provides a PHP replacement layer for the C intl extension that includes additional data from the ICU library symfony/mailer v5.4.34 v6.4.2 Helps sending emails symfony/maker-bundle v1.50.0 v1.52.0 Symfony Maker helps you create empty commands, controllers, form classes, tests and more so you can forget about writing boilerplate code. symfony/mime v5.4.26 v6.4.0 Allows manipulating MIME messages symfony/monolog-bridge v5.4.31 v6.4.0 Provides integration for Monolog with various Symfony components symfony/monolog-bundle v3.10.0 v3.10.0 Symfony MonologBundle symfony/options-resolver v5.4.21 v6.4.0 Provides an improved replacement for the array_replace PHP function symfony/password-hasher v5.4.31 v6.4.0 Provides password hashing utilities symfony/phpunit-bridge v5.4.34 v7.0.2 Provides utilities for PHPUnit, especially user deprecation notices management symfony/polyfill-intl-grapheme v1.28.0 v1.28.0 Symfony polyfill for intl's grapheme_* functions symfony/polyfill-intl-icu v1.28.0 v1.28.0 Symfony polyfill for intl's ICU-related data and classes symfony/polyfill-intl-idn v1.28.0 v1.28.0 Symfony polyfill for intl's idn_to_ascii and idn_to_utf8 functions symfony/polyfill-intl-normalizer v1.28.0 v1.28.0 Symfony polyfill for intl's Normalizer class and related functions symfony/polyfill-mbstring v1.28.0 v1.28.0 Symfony polyfill for the Mbstring extension symfony/polyfill-php72 v1.28.0 v1.28.0 Symfony polyfill backporting some PHP 7.2+ features to lower PHP versions symfony/polyfill-php73 v1.28.0 v1.28.0 Symfony polyfill backporting some PHP 7.3+ features to lower PHP versions symfony/polyfill-php80 v1.28.0 v1.28.0 Symfony polyfill backporting some PHP 8.0+ features to lower PHP versions symfony/polyfill-php81 v1.28.0 v1.28.0 Symfony polyfill backporting some PHP 8.1+ features to lower PHP versions symfony/process v5.4.34 v6.4.2 Executes commands in sub-processes symfony/property-access v5.4.26 v6.4.0 Provides functions to read and write from/to an object or array using a simple string notation symfony/property-info v5.4.24 v6.4.0 Extracts information about PHP class' properties using metadata of popular sources symfony/routing v5.4.34 v6.4.2 Maps an HTTP request to a set of configuration variables symfony/runtime v5.4.26 v6.4.0 Enables decoupling PHP applications from global state symfony/security-acl v3.3.3 v3.3.3 Symfony Security Component - ACL (Access Control List) symfony/security-bundle v5.4.34 v6.4.2 Provides a tight integration of the Security component into the Symfony full-stack framework symfony/security-core v5.4.30 v6.4.0 Symfony Security Component - Core Library symfony/security-csrf v5.4.27 v6.4.0 Symfony Security Component - CSRF Library symfony/security-guard v5.4.27 v5.4.27 Symfony Security Component - Guard symfony/security-http v5.4.31 v6.4.0 Symfony Security Component - HTTP Integration symfony/serializer v5.4.34 v6.4.2 Handles serializing and deserializing data structures, including object graphs, into array structures or other formats like XML and JSON. symfony/service-contracts v2.5.2 v3.4.1 Generic abstractions related to writing services symfony/stopwatch v5.4.21 v6.4.0 Provides a way to profile code symfony/string v5.4.34 v6.4.2 Provides an object-oriented API to strings and deals with bytes, UTF-8 code points and grapheme clusters in a unified way symfony/templating v5.4.21 v6.4.0 Provides all the tools needed to build any kind of template system symfony/translation v5.4.31 v6.4.2 Provides tools to internationalize your application symfony/translation-contracts v2.5.2 v3.4.1 Generic abstractions related to translation symfony/twig-bridge v5.4.34 v6.4.2 Provides integration for Twig with various Symfony components symfony/twig-bundle v5.4.31 v6.4.0 Provides a tight integration of Twig into the Symfony full-stack framework symfony/validator v5.4.34 v6.4.2 Provides tools to validate values symfony/var-dumper v5.4.29 v6.4.2 Provides mechanisms for walking through any arbitrary PHP variable symfony/var-exporter v6.4.2 v6.4.2 Allows exporting any serializable PHP data structure to plain PHP code symfony/web-link v5.4.21 v6.4.0 Manages links between resources symfony/web-profiler-bundle v5.4.34 v6.4.2 Provides a development tool that gives detailed information about the execution of any request symfony/webpack-encore-bundle v2.1.1 v2.1.1 Integration with your Symfony app & Webpack Encore! symfony/yaml v5.4.31 v6.4.0 Loads and dumps YAML files ```
ErrorException:
User Notice: Undefined property: Proxies\__CG__\App\Entity\SonataPageBlock::$lazyObjectState in D:\*****\******\******\sonata\private\vendor\symfony\property-access\PropertyAccessor.php on line 488

  at D:\*****\******\******\sonata\private\vendor\symfony\var-exporter\LazyGhostTrait.php:193
  at Proxies\__CG__\App\Entity\SonataPageBlock->__get('lazyObjectState')
     (D:\*****\******\******\sonata\private\vendor\symfony\property-access\PropertyAccessor.php:488)
  at Symfony\Component\PropertyAccess\PropertyAccessor->readProperty(array(object(SonataPageBlock)), 'lazyObjectState', false)
     (D:\*****\******\******\sonata\private\vendor\symfony\property-access\PropertyAccessor.php:154)
  at Symfony\Component\PropertyAccess\PropertyAccessor->getValue(object(SonataPageBlock), 'lazyObjectState')
     (D:\*****\******\******\sonata\private\vendor\symfony\serializer\Normalizer\ObjectNormalizer.php:136)
  at Symfony\Component\Serializer\Normalizer\ObjectNormalizer->getAttributeValue(object(SonataPageBlock), 'lazyObjectState', null, array('datetime_format' => 'U', 'skip_null_values' => true, 'callbacks' => array('blocks' => object(Closure), 'parent' => object(Closure)), 'cache_key' => false, 'circular_reference_limit_counters' => array('00000000000005400000000000000000' => 1, '00000000000008a70000000000000000' => 1)))
     (D:\*****\******\******\sonata\private\vendor\symfony\serializer\Normalizer\AbstractObjectNormalizer.php:190)
  at Symfony\Component\Serializer\Normalizer\AbstractObjectNormalizer->normalize(object(SonataPageBlock), null, array('datetime_format' => 'U', 'skip_null_values' => true, 'callbacks' => array('blocks' => object(Closure), 'parent' => object(Closure)), 'cache_key' => false, 'circular_reference_limit_counters' => array('00000000000005400000000000000000' => 1, '00000000000008a70000000000000000' => 1)))
     (D:\*****\******\******\sonata\private\vendor\symfony\serializer\Serializer.php:161)
  at Symfony\Component\Serializer\Serializer->normalize(object(SonataPageBlock), null, array('datetime_format' => 'U', 'skip_null_values' => true, 'callbacks' => array('blocks' => object(Closure), 'parent' => object(Closure)), 'cache_key' => false, 'circular_reference_limit_counters' => array('00000000000005400000000000000000' => 1)))
     (D:\*****\******\******\sonata\private\vendor\symfony\serializer\Serializer.php:179)
  at Symfony\Component\Serializer\Serializer->normalize(array(object(SonataPageBlock), object(SonataPageBlock), object(SonataPageBlock), object(SonataPageBlock), object(SonataPageBlock), object(SonataPageBlock), object(SonataPageBlock), object(SonataPageBlock), object(SonataPageBlock), object(SonataPageBlock)), null, array('datetime_format' => 'U', 'skip_null_values' => true, 'callbacks' => array('blocks' => object(Closure), 'parent' => object(Closure)), 'cache_key' => false, 'circular_reference_limit_counters' => array('00000000000005400000000000000000' => 1)))
     (D:\*****\******\******\sonata\private\vendor\symfony\serializer\Normalizer\AbstractObjectNormalizer.php:224)
  at Symfony\Component\Serializer\Normalizer\AbstractObjectNormalizer->normalize(object(SonataPagePage), null, array('datetime_format' => 'U', 'skip_null_values' => true, 'callbacks' => array('blocks' => object(Closure), 'parent' => object(Closure)), 'cache_key' => false, 'circular_reference_limit_counters' => array('00000000000005400000000000000000' => 1)))
     (D:\*****\******\******\sonata\private\vendor\symfony\serializer\Serializer.php:161)
  at Symfony\Component\Serializer\Serializer->normalize(object(SonataPagePage), null, array('datetime_format' => 'U', 'skip_null_values' => true, 'callbacks' => array('blocks' => object(Closure), 'parent' => object(Closure))))
     (D:\*****\******\******\sonata\private\vendor\sonata-project\page-bundle\src\Entity\Transformer.php:100)
  at Sonata\PageBundle\Entity\Transformer->create(object(SonataPagePage), object(SonataPageSnapshot))
     (D:\*****\******\******\sonata\private\vendor\sonata-project\page-bundle\src\Admin\SnapshotAdmin.php:76)
  at Sonata\PageBundle\Admin\SnapshotAdmin->prePersist(object(SonataPageSnapshot))
     (D:\*****\******\******\sonata\private\vendor\sonata-project\admin-bundle\src\Admin\AbstractAdmin.php:404)
  at Sonata\AdminBundle\Admin\AbstractAdmin->create(object(SonataPageSnapshot))
     (D:\*****\******\******\sonata\private\vendor\sonata-project\admin-bundle\src\Controller\CRUDController.php:594)
  at Sonata\AdminBundle\Controller\CRUDController->createAction(object(SiteRequest))
     (D:\*****\******\******\sonata\private\vendor\symfony\http-kernel\HttpKernel.php:163)
  at Symfony\Component\HttpKernel\HttpKernel->handleRaw(object(SiteRequest), 1)
     (D:\*****\******\******\sonata\private\vendor\symfony\http-kernel\HttpKernel.php:75)
  at Symfony\Component\HttpKernel\HttpKernel->handle(object(SiteRequest), 1, true)
     (D:\*****\******\******\sonata\private\vendor\symfony\http-kernel\Kernel.php:202)
  at Symfony\Component\HttpKernel\Kernel->handle(object(SiteRequest))
     (D:\*****\******\******\sonata\web\index.php:26)

SonataPageBlock was only Entity, where I got this error.

VincentLanglet commented 8 months ago

Thanks, it's more an issue with SonataPage then, and the way the serializer works.

Certainly related to https://github.com/sonata-project/SonataPageBundle/pull/1522 cc @Hanmac

Hanmac commented 8 months ago

ugh i need to debug this more

i don't know what the best way with lazy doctrine + serializer would be

i will post when i find out more

Hanmac commented 8 months ago

@VincentLanglet i can't test it right now (i don't have Sonata Page Project at the moment)

but can you check what happens when you add the ugly Doctrine Property to the list of ignored ones? https://github.com/sonata-project/SonataPageBundle/blob/4.x/src/Resources/config/serialization/Model.Block.xml

Hanmac commented 7 months ago

@VincentLanglet can you (or someone else) help me to create an extra UnitTest Case with lazy doctrine enabled so i can test this better?

VincentLanglet commented 7 months ago

(i don't have Sonata Page Project at the moment)

I never used it , but maybe @mesiarm can help you about a reproducer

mesiarm commented 7 months ago

@VincentLanglet can you (or someone else) help me to create an extra UnitTest Case with lazy doctrine enabled so i can test this better?

I never did it before

Hanmac commented 7 months ago

@mesiarm can you post part of your doctrine and/or serializer config so i can try to reproduce your error in a test case?

mesiarm commented 7 months ago
doctrine.yaml ``` doctrine: dbal: url: '%env(resolve:DATABASE_URL)%' # IMPORTANT: You MUST configure your server version, # either here or in the DATABASE_URL env var (see .env file) #server_version: '13' orm: auto_generate_proxy_classes: true enable_lazy_ghost_objects: true entity_managers: default: auto_mapping: true naming_strategy: doctrine.orm.naming_strategy.underscore_number_aware dql: numeric_functions: rand: DoctrineExtensions\Query\Mysql\Rand mappings: gedmo_translatable: type: annotation prefix: Gedmo\Translatable\Entity dir: "%kernel.project_dir%/vendor/gedmo/doctrine-extensions/src/Translatable/Entity" alias: GedmoTranslatable # (optional) it will default to the name set for the mapping is_bundle: false gedmo_translator: type: annotation prefix: Gedmo\Translator\Entity dir: "%kernel.project_dir%/vendor/gedmo/doctrine-extensions/src/Translator/Entity" alias: GedmoTranslator # (optional) it will default to the name set for the mapping is_bundle: false SonataUserBundle: ~ SonataPageBundle: ~ SonataMediaBundle: ~ ProdigiousSonataMenuBundle: ~ App: is_bundle: false type: attribute dir: '%kernel.project_dir%/src/Entity' prefix: 'App\Entity' alias: App ```

This is my doctrine.yaml config. I dont have serializer config

haivala commented 7 months ago

I'm using latest Sonata bundles and Symfony 6.4. I have page that has only one Simple Text Block from Block bundle and when I'm creating a snapshot for that page. I get User Notice: Undefined property: Proxies\__CG__\App\Entity\SonataPageBlock::$lazyObjectState in symfony/vendor/symfony/property-access/PropertyAccessor.php on line 418 Setting enable_lazy_ghost_objects: false fixes this error.

Hanmac commented 7 months ago

@haivala yeah i 'm trying to make a reproducable test case, but i couldn't got the Unit tests to throw that Error

I think one way would be to Force the Collection to be loaded, but for this i need the unit tests to check

haivala commented 7 months ago

I'm just wondering: Is this only thing that needs a fix for us to be able to allow Symfony 7?

Hanmac commented 7 months ago

@haivala i haven't time yet to make it reproducible probably because the testcases uses different orm

can you test it what happens if you make the Page Collection loaded before this point? https://github.com/sonata-project/SonataPageBundle/blob/4.x/src/Entity/Transformer.php#L100

something like: $page->getChildren()->getValues() $page->getBlocks()->getValues()

before ?

(i might need to check how to load all the Children, and all the block children?)

haivala commented 6 months ago

I'm just wondering: Is this only thing that needs a fix for us to be able to allow Symfony 7?

Noticed that this is missing ORM 3 support

haivala commented 5 months ago

@Hanmac Now I get error Ignore on "Proxies\__CG__\App\Entity\Sonata\SonataPageBlock::__setInitialized()" cannot be added. Ignore can only be added on methods beginning with "get", "is", "has" or "set".

Hanmac commented 5 months ago

@Hanmac Now I get error Ignore on "Proxies\__CG__\App\Entity\Sonata\SonataPageBlock::__setInitialized()" cannot be added. Ignore can only be added on methods beginning with "get", "is", "has" or "set".

that looks like a new Bug in Symfony Serializer again, __setInitialized doesn't exist in the Sonata Code

Please Open the Issue on the Symfony Repo

Edit: there is alreaddy one: https://github.com/symfony/symfony/issues/54477

VincentLanglet commented 5 months ago

The issue https://github.com/symfony/symfony/issues/54477 is solved ; does it solve your issue ?

eerison commented 4 months ago

The issue symfony/symfony#54477 is solved ; does it solve your issue ?

I guess need to wait for Symfony 5.4.39 and 6.4.7 https://github.com/symfony/symfony/pull/54485#issuecomment-2079266369

haivala commented 4 months ago

I tested and it seems to work with the new serializer

eerison commented 4 months ago

The issue symfony/symfony#54477 is solved ; does it solve your issue ?

I guess need to wait for Symfony 5.4.39 and 6.4.7 symfony/symfony#54485 (comment)

it was released.