8000 bug #28917 [DoctrineBridge] catch errors while converting to db value… · symfony/symfony@7be8ca5 · GitHub
[go: up one dir, main page]

Skip to content

Commit 7be8ca5

Browse files
committed
bug #28917 [DoctrineBridge] catch errors while converting to db values in data collector (alekitto)
This PR was merged into the 2.8 branch. Discussion ---------- [DoctrineBridge] catch errors while converting to db values in data collector | Q | A | ------------- | --- | Branch? | 2.8 | Bug fix? | yes | New feature? | no | BC breaks? | no | Deprecations? | no | Tests pass? | yes | License | MIT When the profiler is enabled and collecting doctrine queries data, if a query fails because of `ConversionException` or another error thrown while resolving parameters, the data collector is also throwing the same error. This should fix this case. The tests for this case cannot be executed in 5.4 because Doctrine 2.5 fails with a fatal error in `DateType`. Commits ------- 61c4531 [DoctrineBridge] catch errors while converting to db values in data collector
2 parents 18b3a52 + 61c4531 commit 7be8ca5

File tree

2 files changed

+18
-2
lines changed

2 files changed

+18
-2
lines changed

src/Symfony/Bridge/Doctrine/DataCollector/DoctrineDataCollector.php

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@
1313

1414
use Doctrine\Common\Persistence\ManagerRegistry;
1515
use Doctrine\DBAL\Logging\DebugStack;
16+
use Doctrine\DBAL\Types\ConversionException;
1617
use Doctrine\DBAL\Types\Type;
1718
use Symfony\Component\HttpFoundation\Request;
1819
use Symfony\Component\HttpFoundation\Response;
@@ -132,7 +133,14 @@ private function sanitizeQuery($connectionName, $query)
132133
}
133134
if ($type instanceof Type) {
134135
$query['types'][$j] = $type->getBindingType();
135-
$param = $type->convertToDatabaseValue($param, $this->registry->getConnection($connectionName)->getDatabasePlatform());
136+
try {
137+
$param = $type->convertToDatabaseValue($param, $this->registry->getConnection($connectionName)->getDatabasePlatform());
138+
} catch (\TypeError $e) {
139+
// Error thrown while processing params, query is not explainable.
140+
$query['explainable'] = false;
141+
} catch (ConversionException $e) {
142+
$query['explainable'] = false;
143+
}
136144
}
137145
}
138146

src/Symfony/Bridge/Doctrine/Tests/DataCollector/DoctrineDataCollectorTest.php

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@
1212
namespace Symfony\Bridge\Doctrine\Tests\DataCollector;
1313

1414
use Doctrine\DBAL\Platforms\MySqlPlatform;
15+
use Doctrine\DBAL\Version;
1516
use PHPUnit\Framework\TestCase;
1617
use Symfony\Bridge\Doctrine\DataCollector\DoctrineDataCollector;
1718
use Symfony\Component\HttpFoundation\Request;
@@ -120,7 +121,7 @@ public function testSerialization($param, $types, $expected, $explainable)
120121

121122
public function paramProvider()
122123
{
123-
return array(
124+
$tests = array(
124125
array('some value', array(), 'some value', true),
125126
array(1, array(), 1, true),
126127
array(true, array(), true, true),
@@ -129,6 +130,13 @@ public function paramProvider()
129130
array(fopen(__FILE__, 'r'), array(), 'Resource(stream)', false),
130131
array(new \SplFileInfo(__FILE__), array(), 'Object(SplFileInfo)', false),
131132
);
133+
134+
if (version_compare(Version::VERSION, '2.6', '>=')) {
135+
$tests[] = array('this is not a date', array('date'), 'this is not a date', false);
136+
$tests[] = array(new \stdClass(), array('date'), 'Object(stdClass)', false);
137+
}
138+
139+
return $tests;
132140
}
133141

134142
private function createCollector($queries)

0 commit comments

Comments
 (0)
0