-
-
Notifications
You must be signed in to change notification settings - Fork 1.3k
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
Skip empty expression parts #4282
Comments
@BenMorel can you please have a look? |
I’m not sure to see the value in providing this check; when is it useful IRL? There are many invalid WHERE expressions, an empty string is just one of them; and it’s not the responsibility of this library to validate them. If anything, I’d rather throw an exception rather than silently discarding the value. But if you really ask me, I would keep the current behaviour and document the BC break. Unless there’s a good case for this, obviously! |
I see, it's the @BenMorel while I agree with your point, it is a BC break which shouldn't be introduced in |
Ah, sorry, I realize now that this has been included in 2.x as well. I only had 3.0 in mind. |
Thank you! |
Could it be that this still fails?
This works in 2.10 |
@liayn This should work in |
If I'm not mistaken, the fix (and tests) only cover cases where there is at least one non empty argument. In his case, there is only one empty condition and no non empty prior call to The unshift here: https://github.com/doctrine/dbal/pull/4286/files#diff-305699f4a9180da213eb29c5671ab925R839 produces Edit: shouldn't we return out early if |
Unless I missed something, the fix should cover all cases. Could you please provide a failing test case? Not even as a PR, you can just copy/paste the code here. If there's a regression, I'll fix it. |
Reproducer: diff --git a/tests/Doctrine/Tests/DBAL/Query/QueryBuilderTest.php b/tests/Doctrine/Tests/DBAL/Query/QueryBuilderTest.php
index 038097c89..d70127625 100644
--- a/tests/Doctrine/Tests/DBAL/Query/QueryBuilderTest.php
+++ b/tests/Doctrine/Tests/DBAL/Query/QueryBuilderTest.php
@@ -950,6 +950,18 @@ class QueryBuilderTest extends DbalTestCase
$qb->getSQL();
}
+ public function testAndWhereEmptyString(): void
+ {
+ $qb = new QueryBuilder($this->conn);
+
+ $qb->select('id')
+ ->from('foo');
+
+ $qb->andWhere('');
+
+ self::assertSame('SELECT id FROM foo', $qb->getSQL());
+ }
+
public function testAndWhereEmptyStringStartingWithEmptyExpression(): void
{
$qb = new QueryBuilder($this->conn);
@@ -975,6 +987,18 @@ class QueryBuilderTest extends DbalTestCase
self::assertSame('SELECT id FROM foo WHERE (a = b) AND (c = d)', $qb->getSQL());
}
+ public function testOrWhereEmptyString(): void
+ {
+ $qb = new QueryBuilder($this->conn);
+
+ $qb->select('id')
+ ->from('foo');
+
+ $qb->orWhere('');
+
+ self::assertSame('SELECT id FROM foo', $qb->getSQL());
+ }
+
public function testOrWhereEmptyStringStartingWithEmptyExpression(): void
{
$qb = new QueryBuilder($this->conn); |
Thanks for the test case, @discordier! I can confirm that it fails indeed. But I'm afraid it also fails on 2.10.x, so this is not a regression:
Do we want to fix this for 2.10.x, @morozov? |
https://github.com/georgringer/news/blob/e16807909889336b3c510f4e30ec630492fdcfe3/Classes/Backend/RecordList/RecordListConstraint.php#L251 |
I have not tested against 2.10.x, I was simply providing a test case for #4282 (comment). I did not check against the prior behavior. Sorry for the noise. I'll have a look at #4282 (comment) and try to come up with a more specific one. |
The difference is that we have a |
So is there still a regression now, @liayn? |
He is right: diff --git a/tests/Doctrine/Tests/DBAL/Query/QueryBuilderTest.php b/tests/Doctrine/Tests/DBAL/Query/QueryBuilderTest.php
index 038097c89..383c069d5 100644
--- a/tests/Doctrine/Tests/DBAL/Query/QueryBuilderTest.php
+++ b/tests/Doctrine/Tests/DBAL/Query/QueryBuilderTest.php
@@ -950,6 +950,19 @@ class QueryBuilderTest extends DbalTestCase
$qb->getSQL();
}
+ public function testWhereExpressionAndWhereEmptyString(): void
+ {
+ $qb = new QueryBuilder($this->conn);
+
+ $qb->select('id')
+ ->from('foo')
+ ->where('a = b');
+
+ $qb->andWhere('');
+
+ self::assertSame('SELECT id FROM foo WHERE a = b', $qb->getSQL());
+ }
+
public function testAndWhereEmptyStringStartingWithEmptyExpression(): void
{
$qb = new QueryBuilder($this->conn);
@@ -975,6 +988,19 @@ class QueryBuilderTest extends DbalTestCase
self::assertSame('SELECT id FROM foo WHERE (a = b) AND (c = d)', $qb->getSQL());
}
+ public function testWhereExpressionOrWhereEmptyString(): void
+ {
+ $qb = new QueryBuilder($this->conn);
+
+ $qb->select('id')
+ ->from('foo')
+ ->where('a = b');
+
+ $qb->orWhere('');
+
+ self::assertSame('SELECT id FROM foo WHERE a = b', $qb->getSQL());
+ }
+
public function testOrWhereEmptyStringStartingWithEmptyExpression(): void
{
$qb = new QueryBuilder($this->conn); dbal 2.11.x:
dbal 2.10.x:
Interestingly, only the |
@discordier Thank you. Fixed in #4330. |
any hints on when you will release a bugfix version? Trying to decide whether we can wait for it or need to pin the version to 2.10.x. It would be really nice to get a date or maybe a timeframe (tomorrow, in 6 weeks, in less than 6 months, ... you get the idea?) Thank you very much for all the work done. |
@maddy2101 I plan to release it this week. See the associated milestone. |
This thread has been automatically locked since there has not been any recent activity after it was closed. Please open a new issue for related bugs. |
Bug Report
Summary
The commit 1d50325 introduced a breaking change.
CompsiteExpression->with() directly adds
parts
, whereas the old CompositeExpression->addMultiple() utilized CompositeExpression->add() which had anempty
-check.has a guard
see https://github.com/doctrine/dbal/blob/2.11.x/lib/Doctrine/DBAL/Query/Expression/CompositeExpression.php#L100
has no guard
see https://github.com/doctrine/dbal/blob/2.11.x/lib/Doctrine/DBAL/Query/Expression/CompositeExpression.php#L126
Current behaviour
parts
with empty-string result inAND ()
which is an invalid where-expression.How to reproduce
andWhere
Expected behaviour
Do not add empty where conditions in
CompositeExpression->with()
asCompositeExpression->add()
did.The text was updated successfully, but these errors were encountered: