Quote parts of the table name#12088
Conversation
|
Fails on Postgres with: https://github.com/doctrine/orm/actions/runs/16606300367/job/46978995125?pr=12088#step:7:162 Now let's attempt a fix. |
|
Huh so now the test is fixed, bug another test introduced in 54b3c05 is broken. |
27eaf43 to
d0d1a71
Compare
|
I'm temporarily reverting #11811 to see if that gives me a green build, I'm starting to have doubts about that. |
|
🤯 it doesn't… what the hell? |
|
Ah no, the revert works, but for some reason, the test I'm adding has a side effect 🤔 |
|
Ah that's because the same schema name ( |
|
Instead of altering my new test to change the schema, I'm adding a new test case to the existing test, since it tests more things. |
| @@ -41,9 +44,17 @@ public function getTableName(ClassMetadata $class, AbstractPlatform $platform): | |||
| $tableName = $class->table['schema'] . '.' . $class->table['name']; | |||
| } | |||
There was a problem hiding this comment.
Just realized this is what's causing the infamous dot. Instead of inlining quoteIdentifier(), let me try to modify this.
|
Reproduced the failure by downgrading DBAL to v3. |
| { | ||
| return isset($definition['quoted']) | ||
| ? $platform->quoteSingleIdentifier($definition['sequenceName']) | ||
| ? implode('.', array_map( |
There was a problem hiding this comment.
I have little understanding of what tradeoffs are acceptable here, so I cannot provide a reasonable feedback.
Every implode('.', $name) is a potential bug, which is why quoteIdentifier() was deprecated in the first place.
Assuming that it fixes the reported issue (which is covered by a new test), the patch looks good.
There was a problem hiding this comment.
I initially wrote a separate test just for the reported issue, and the other part of the patch fixed it. This is here to fix another issue found when I decided to reuse the existing test, if I recall correctly. In any case, I think that on a patch branch, doing this is the right thing, but that on the next minor, we might want deprecate relying on that implode. This will require further analysis as to the ramification of the deprecation though.
| if ($this->_em->getConnection()->getDatabasePlatform()->supportsSchemas()) { | ||
| $fullTableName = sprintf('%s.%s', $expectedSchemaName, $expectedTableName); | ||
| $fullTableName = sprintf( | ||
| $isQuoted ? '"%s"."%s"' : '%s.%s', | ||
| $expectedSchemaName, | ||
| $expectedTableName, | ||
| ); | ||
| } else { |
There was a problem hiding this comment.
This kind of test looks... not really useful. On the one hand, it's an integration test that that covers implementation details, which in turn depend on the environment, so it's hard to reason whether it provides the right feedback or not. On the other, there are two levels of code branching (if and ?), but a proper test shouldn't have any conditional logic.
Would it make sense to convert it to a unit test and make the expected values explicit?
Also, the dependency of the result on supportsSchemas() looks a bit inadequate. The result should depend only on the input (i.e. the class metadata).
There was a problem hiding this comment.
Good points. To elaborate on your last point, the test is skipped unless the database supports schemas:
orm/tests/Tests/ORM/Functional/Ticket/DDC2825Test.php
Lines 28 to 30 in 0f32569
So it makes no sense to have this if statement:
orm/tests/Tests/ORM/Functional/Ticket/DDC2825Test.php
Lines 44 to 48 in 0f32569
This test definitely needs some love, and I will start by removing this if statement.
There was a problem hiding this comment.
I will look into doing the improvements you mentioned, but for now, here is a PR that addresses the issue in my last message. #12094
There was a problem hiding this comment.
@morozov I did the conversion to unit tests, please take another look.
In aa141bf, I wrongly assumed that $tableName would never contain a dot as I was not able to write a test that caused that to happen. The secret recipe appears to be to define a schema and to quote the table name. To fix it for the table name, I am calling quoteSingleIdentifier() before doing the concatenation between schema name and table name. To fix it for the sequence name, which seems only useful when using DBAL 3 for some reason, I reuse some of the logic of the deprecated method. Fixes doctrine#12041
That test was testing too many thing and not really making it clear what the expected output was, given some output. Instead, let us create 2 tests, each pertaining to the class under test.
This comment is rendered useless by the phpdoc comment below it. Instead, we can comment on what exactly "quoted" means.
|
Hey, coming from #12041, I just wanted to say thank you for your hard work to fix the issue! I really appreciate this :) |
In #11811, I wrongly assumed that
$tableNamewould never contain a dot as I was not able to write a testthat caused that to happen.
The secret recipe appears to be to define a schema and to quote the
table name.
Fixes #12041