Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Appearance settings

Commit 61c4531

Browse filesBrowse files
committed
[DoctrineBridge] catch errors while converting to db values in data collector
1 parent e4a7fd8 commit 61c4531
Copy full SHA for 61c4531

File tree

Expand file treeCollapse file tree

2 files changed

+18
-2
lines changed
Filter options
Expand file treeCollapse file tree

2 files changed

+18
-2
lines changed

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

Copy file name to clipboardExpand all lines: src/Symfony/Bridge/Doctrine/DataCollector/DoctrineDataCollector.php
+9-1Lines 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

Copy file name to clipboardExpand all lines: src/Symfony/Bridge/Doctrine/Tests/DataCollector/DoctrineDataCollectorTest.php
+9-1Lines 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)
Morty Proxy This is a proxified and sanitized view of the page, visit original site.