Commit 4f927755 authored by Jérome Perrin's avatar Jérome Perrin

ZSQLCatalog: reject unhandled search value types.

Raise an exception instead of casting to string unhandled search values,
because it's more likely that caller accidentally passed a wrong value.
parent 0ed7ff48
Pipeline #33580 failed with stage
in 0 seconds
...@@ -1238,6 +1238,14 @@ class TestERP5Catalog(ERP5TypeTestCase, LogInterceptor): ...@@ -1238,6 +1238,14 @@ class TestERP5Catalog(ERP5TypeTestCase, LogInterceptor):
[x.getObject() for x in self.getCatalogTool()( [x.getObject() for x in self.getCatalogTool()(
parent_title=person_module.getTitle())]) parent_title=person_module.getTitle())])
def test_unhandled_search_value(self):
class UnhandledClass:
pass
with self.assertRaisesRegex(
TypeError,
'Unhandled value class: UnhandledClass.*'):
self.getCatalogTool()(title=UnhandledClass())
def test_45_QueryAndComplexQuery(self): def test_45_QueryAndComplexQuery(self):
""" """
""" """
......
...@@ -29,7 +29,6 @@ ...@@ -29,7 +29,6 @@
############################################################################## ##############################################################################
import six import six
from six import string_types as basestring from six import string_types as basestring
from zLOG import LOG
from DateTime import DateTime from DateTime import DateTime
from Products.ZSQLCatalog.interfaces.operator import IOperator from Products.ZSQLCatalog.interfaces.operator import IOperator
from Products.ZSQLCatalog.Utils import sqlquote as escapeString from Products.ZSQLCatalog.Utils import sqlquote as escapeString
...@@ -45,8 +44,7 @@ def valueDateTimeRenderer(value): ...@@ -45,8 +44,7 @@ def valueDateTimeRenderer(value):
return '"%s"' % (value.toZone('UTC').ISO(), ) return '"%s"' % (value.toZone('UTC').ISO(), )
def valueDefaultRenderer(value): def valueDefaultRenderer(value):
LOG('OperatorBase', 0, 'Unhandled value class: %s (%r). Converted to string and escaped.' % (value.__class__.__name__, value)) raise TypeError('Unhandled value class: %s (%r)' % (value.__class__.__name__, value))
return escapeString(str(value))
def valueNoneRenderer(value): def valueNoneRenderer(value):
return 'NULL' return 'NULL'
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment