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

BC Break if the storeEmptyArray is not defined in the mapping #2588

Closed
frenchcomp opened this issue Nov 24, 2023 · 8 comments
Closed

BC Break if the storeEmptyArray is not defined in the mapping #2588

frenchcomp opened this issue Nov 24, 2023 · 8 comments
Assignees
Labels
Milestone

Comments

@frenchcomp
Copy link

BC Break Report

The key 'store-empty-array' in a mapping about a collection is not mandatory with 2.5.5 and lower version, but it is mandatory with 2.6

Q A
BC Break yes
Version 2.6.0

Summary

We can not upgrade a code using Doctrine ODM 2.5.5 and lower with the new version 2.6, because the mapping option 'store-empty-array' added is mandatory in the CollectionPersister

Previous behavior

The option does not exist

Current behavior

PHP throw a warning for an non existent key : Warning: Undefined array key "storeEmptyArray"
Maybe add a default option in doctrine-mongo-mapping.xsd and in the CollectionPersister, replace line 72
if ($mapping['storeEmptyArray']) { to if (!empty($mapping['storeEmptyArray'])) {

How to reproduce

Use a collection compliant with 2.5 but not 2.6 like


@malarzm
Copy link
Member

malarzm commented Nov 24, 2023

@frenchcomp we have plenty of tests that are not using the new functionality. Have you regenerated metadata after upgrading ODM?

@frenchcomp
Copy link
Author

Yes all caches, included OPCache, was cleaned and all metadata will be regenerated.
I had also test with a new clone with a personnal project.
I do not use PHP Attributes, only XML mapping. The attribute has the default value, but not the XML mapping

@alcaeus
Copy link
Member

alcaeus commented Nov 24, 2023

The attribute has the default value, but not the XML mapping

I created a small test in AbstractMappingDriverTestCase, which checks the mapping for both referenced and embedded mappings, and it passed in all mapping drivers.

Please provide more information regarding the mapping that causes the error. Is it a ReferenceMany or a EmbedMany relationship? Did you confirm that metadata was freshly loaded and not loaded from cache?

Nevermind, I already had a potential fix in place. I confirmed the issue and will have a bug fix in a moment.

@frenchcomp
Copy link
Author

I had the default value into the xml but the bug is still here.
It's en embedded collection.

@frenchcomp
Copy link
Author

A breakpoint into public function setOwner(object $document, array $mapping) in lib/Doctrine/ODM/MongoDB/PersistentCollection/PersistentCollectionTrait.php, the $mapping array has not the key storeEmptyArray
The key is not present in the classmetaddata of the parent

@frenchcomp
Copy link
Author

array ( 'type' => 'many', 'embedded' => true, 'targetDocument' => NULL, 'collectionClass' => NULL, 'name' => 'authData', 'strategy' => 'pushAll', 'nullable' => false, 'discriminatorField' => 'type', 'fieldName' => 'authData', 'isCascadeRemove' => true, 'isCascadePersist' => true, 'isCascadeRefresh' => true, 'isCascadeMerge' => true, 'isCascadeDetach' => true, 'association' => 4, 'isOwningSide' => true, 'isInverseSide' => false, )

dump of $mapping in lib/Doctrine/ODM/MongoDB/Mapping/ClassMetadata.php line 2390 for the embedded collection (during the call to loadMetadataForClass after clean all caches)

@malarzm
Copy link
Member

malarzm commented Nov 24, 2023

Fixed in #2590, will cut a release soon. Thanks @frenchcomp for living on the edge and finding this one! 🥃

@malarzm malarzm closed this as completed Nov 24, 2023
@frenchcomp
Copy link
Author

Great job ! Thanks :)

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

No branches or pull requests

3 participants