-
Notifications
You must be signed in to change notification settings - Fork 2.5k
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
Prevents incorrect table aliases #8112
Prevents incorrect table aliases #8112
Conversation
if (isset($this->currentPersisterContext->sqlTableAliases[$tableName])) { | ||
return $this->currentPersisterContext->sqlTableAliases[$tableName]; | ||
if (isset($this->currentPersisterContext->sqlTableAliases[strtolower($tableName)])) { | ||
return $this->currentPersisterContext->sqlTableAliases[strtolower($tableName)]; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This is a map from FQCN to table alias, I'm not sure why $tableName
is not named $fqcn
🤔
When one uses a discriminator map with a valid, but incorrectly cased, class name (Foo\\Bar\\baz instead of Foo\\Bar\\baz) for instance, the class metadata won't complain (php being case insensitive when it comes to class name). However, it will complain if the class does not exist. This will lead to "exotic" table alias being generated when querying the parent class because the sqlTableAliases won't contain the wrongly typed classname. Example: SELECT t0.id as id_0, ..., t1.name as name_10, t11.thing as thing_11...
698f125
to
d2ffa63
Compare
When a defined subclass has a case typo, the query builder will be lost and will generate exotic table alias. This commit fixes the issue at the root by prohibiting case typo in discriminator map. See doctrine#8112 for the consequence of such typo.
Related to #8122 |
When a defined subclass has a case typo, the query builder will be lost and will generate exotic table alias. This commit fixes the issue at the root by prohibiting case typo in discriminator map. See doctrine#8112 for the consequence of such typo.
Do you really mean to target |
One might consider this as a BC break, don't you think? 🤔 However, a quick search shows that this Nonetheless, please note that the underlying problem could also be fixed by merging #8122 (which prevent case typo in the discriminator map to happen in the first place). Both PRs could be merged as well, I guess 🤔 I am quite opened to suggestion here, as long as this or (non exclusive) the other PR makes it to |
BTW, do you know what's going on with the CI? It seems broken on master as well |
I'll ask internally but I think I already did some time ago 😅 |
When a defined subclass has a case typo, the query builder will be lost and will generate exotic table alias. This commit fixes the issue at the root by prohibiting case typo in discriminator map. See doctrine#8112 for the consequence of such typo.
I would consider this a BC break if the changes are breaking any tests. If BTW: Tests would be nice. |
I agree. However, after checking in the codebase, the I believe the property is public for performance purpose. If so, introducing a mutator (and reducing visibility of the prop) is not really possible. Furthermore, the initial issue can be fixed by #8122. Consequently, I would suggest to close this PR. |
When a defined subclass has a case typo, the query builder will be lost and will generate exotic table alias. This commit fixes the issue at the root by prohibiting case typo in discriminator map. See doctrine#8112 for the consequence of such typo.
* Prevents incorrect table aliases to be generated When a defined subclass has a case typo, the query builder will be lost and will generate exotic table alias. This commit fixes the issue at the root by prohibiting case typo in discriminator map. See #8112 for the consequence of such typo. * Controls growing rate of the abstract test class * Fixes incorrect test case The Cube class must be autoloaded with the correct case, otherwise composer autoloader will complain. * Removes non architecture compliant code See https://github.com/doctrine/orm/pull/8122/files#r423952247 * Ensures discriminator map is case sensitive
Fixed by #8122 |
When one uses a discriminator map with a valid, but incorrectly cased,
classname (
Foo\Bar\baz
instead ofFoo\Bar\Baz
for instance), theclass metadata won't complain (php being case insensitive when it comes
to class name). However, it will complain if the class does not exist.
This will lead to "exotic" table alias being generated when querying the
parent class because the
sqlTableAliases
won't contain the wrongly typedclassname.
Here's an error example:
t16
should bet2
This is a quite hard to debug issue as the typo is most of the time quite hard to spot and the error (triggered by the db itself) doesn't make you think about a mapping issue at first sight.
I don't think this is an issue in the metadata loader, as
class_exists
is case insensitive by design, so should probably be this internal map. EDIT: I have switched side on this questionI've scratched my head for a while to know where I could add a test case to show you exactly the issue, but I couldn't. Please point me to the right direction if you think this fix should make it to master.
Thanks 👋