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

Detect invalid indexBy configuration in the SchemaValidator #11610

Draft
wants to merge 4 commits into
base: 3.2.x
Choose a base branch
from

Conversation

janklan
Copy link

@janklan janklan commented Sep 24, 2024

Fixes #11608

@janklan janklan changed the title Bugfix 11608 Detect invalid indexBy configuration in the SchemaValidator Sep 24, 2024
Copy link
Member

@greg0ire greg0ire left a comment

Choose a reason for hiding this comment

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

What Psalm reports seems to be a bug… I used psalm-trace to troubleshoot it, and got a huge type definition. I was able to fix it with /* @psalm-var ToManyAssociationMapping $assoc */, but I should not have to. If you could make a minimal reproducer with psalm.dev and report it, that would help.


/**
* GH11608 Tests whether the Schema validator picks up on invalid mapping. The entities are intentionally
* invalid, and so for the purpose of this test case, those entities should be ignored.
Copy link
Member

Choose a reason for hiding this comment

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

Then I'd avoid creating a model set entirely. There are plenty of tests that don't.

@janklan
Copy link
Author

janklan commented Sep 25, 2024

Cheers, will do re psalm.

Do you know if there is another test case I could salvage to learn about how to test the SchemaValidator without a model set?


$errors = $validator->validateClass($this->_em->getClassMetadata($className));

var_dump($errors);
Copy link
Member

Choose a reason for hiding this comment

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

This needs to go.

Copy link
Author

Choose a reason for hiding this comment

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

Whoops.

@greg0ire
Copy link
Member

Do you know if there is another test case I could salvage to learn about how to test the SchemaValidator without a model set?

I suppose calling createSchemaForModels should be enough


if ($assoc->isIndexed()) {
$joinColumns = array_column($targetMetadata->getAssociationMappings(), 'joinColumns');
$joinColumns = array_column($joinColumns, 0);
Copy link
Member

Choose a reason for hiding this comment

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

shouldn't it take all join columns into account instead ?

Copy link
Author

Choose a reason for hiding this comment

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

I guess it should. I didn't realise/think there could be multiple join columns. Thanks.

Comment on lines +284 to +285
$joinColumns = array_column($joinColumns, 'name');

Copy link
Member

Choose a reason for hiding this comment

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

I suggest using a foreach loop instead of several successive array_columns, allowing to loop once

Copy link
Author

@janklan janklan Sep 25, 2024

Choose a reason for hiding this comment

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

I'm not sure I follow the allowing to loop once: $targetMetadata->getAssociationMappings() returns a multi-dimensional array. I'll have to have [probably three] nested foreach loops to gather all the data anyway.

@janklan
Copy link
Author

janklan commented Sep 25, 2024

I suppose calling createSchemaForModels should be enough

I tried that, but then the EntityManager loaded also other tables from some default model set. Is there a way to disable that? I found none. Hence, the custom model set.

@greg0ire
Copy link
Member

I tried that, but then the EntityManager loaded also other tables from some default model set. Is there a way to disable that? I found none. Hence, the custom model set.

I find that extremely surprising. Can you maybe push a branch that I could inspect to see the error?

@janklan janklan marked this pull request as draft September 26, 2024 23:47
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.

Schema validator doesn't report invalid indexBy configuration.
3 participants