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

fix: Don't process subclass indexes with SingleCollection inheritance #2573

Open
wants to merge 2 commits into
base: 2.10.x
Choose a base branch
from

Conversation

buffcode
Copy link
Contributor

@buffcode buffcode commented Nov 5, 2023

Q A
Type bug
BC Break no
Fixed issues #2561

Summary

When using single collection inheritance, all sub classes are processed as well and indexes get dropped or re-created, depending on class order.

With this PR only the parent classes are processed and will ensure the indexes of all subclasses.

@buffcode buffcode force-pushed the fix/2.5.x-single-collection-indexes branch from 152a906 to a9137a6 Compare November 5, 2023 21:39
@buffcode
Copy link
Contributor Author

buffcode commented Nov 5, 2023

@malarzm I am not too familiar with psalm and how to fix this CI error, as it appears to be in the baseline file already:

Error: tests/Doctrine/ODM/MongoDB/Tests/SchemaManagerTest.php:330:26: InternalClass: MongoDB\Model\IndexInfoIteratorIterator is internal to MongoDB but called from Doctrine\ODM\MongoDB\Tests\SchemaManagerTest (see https://psalm.dev/174)

Error: tests/Doctrine/ODM/MongoDB/Tests/SchemaManagerTest.php:330:26: InternalMethod: Constructor MongoDB\Model\IndexInfoIteratorIterator::__construct is internal to MongoDB, MongoDB, and MongoDB but called from Doctrine\ODM\MongoDB\Tests\SchemaManagerTest::testUpdateDocumentIndexesShouldCreateIndexesFromMappedSuperclass (see https://psalm.dev/175)

Copy link
Member

@malarzm malarzm left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

As for the psalm error please try updating baseline (vendor/bin/psalm --threads=$(nproc) --php-version=8.1 --update-baseline --set-baseline=psalm-baseline.xml) and we'll see what it produces. Most probably it was allowing single usages of offending code and now there will be multiple :)

$this->addInheritedIndexes($class, $parent);
if ($parent->isMappedSuperclass) {
// only inherit indexes if parent won't apply them itself
$this->addInheritedIndexes($class, $parent);
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We can't do such a thing as it changes produced ClassMetadata too much:, especially for a patch release. I'm not sure yet if the change would be OK in a minor patch anyway.

} else {
continue;
}
if ($class->isInheritanceTypeSingleCollection()) {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'd add a failsafe throwing an \InvalidArgumentException when a document that has $class->parentClasses is passed here

foreach ($processClasses as $class) {
$visited[$class->name] = true;

$indexes = array_merge($indexes, $this->prepareIndexes($class));
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

If I'm not mistaken we should be able to work around my first comment here by applying array_unique or calculating some kind of key for an index that's shared between classes

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This will be dirtier than what you're proposing but we're not changing behaviour that was established for years

@alcaeus alcaeus changed the base branch from 2.5.x to 2.10.x September 20, 2024 12:42
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants