[Erp5-report] r34685 vincent - in /erp5/trunk/products/ZSQLCatalog: Query/ tests/
nobody at svn.erp5.org
nobody at svn.erp5.org
Tue Apr 20 14:58:12 CEST 2010
Author: vincent
Date: Tue Apr 20 14:58:10 2010
New Revision: 34685
URL: http://svn.erp5.org?rev=34685&view=rev
Log:
Provide backward compatilibity with older ZSQLCatalog.
In older ZSQLCatalog versions (pre-r25706), values fetched via
select_expression='catalog.simulation_state'
were accessible on brain as "brain.simulation_state". In current catalog,
this became "getattr(brain, 'catalog.simulation_state')" and hence broke
compatibility somewhat. This patch fixes this problem by stripping table
name from the generated alias.
Note: the table name is only stripped from implicit aliases, never from
explicit ones.
Modified:
erp5/trunk/products/ZSQLCatalog/Query/EntireQuery.py
erp5/trunk/products/ZSQLCatalog/tests/testSQLCatalog.py
Modified: erp5/trunk/products/ZSQLCatalog/Query/EntireQuery.py
URL: http://svn.erp5.org/erp5/trunk/products/ZSQLCatalog/Query/EntireQuery.py?rev=34685&r1=34684&r2=34685&view=diff
==============================================================================
--- erp5/trunk/products/ZSQLCatalog/Query/EntireQuery.py [utf8] (original)
+++ erp5/trunk/products/ZSQLCatalog/Query/EntireQuery.py [utf8] Tue Apr 20 14:58:10 2010
@@ -115,6 +115,9 @@
for alias, raw_column in self.select_dict.iteritems():
if raw_column is None:
column = alias
+ if '.' in alias:
+ # If given column is pre-mapped, strip table name from its alias.
+ _, alias = alias.replace('`', '').split('.')
else:
column = raw_column
try:
Modified: erp5/trunk/products/ZSQLCatalog/tests/testSQLCatalog.py
URL: http://svn.erp5.org/erp5/trunk/products/ZSQLCatalog/tests/testSQLCatalog.py?rev=34685&r1=34684&r2=34685&view=diff
==============================================================================
--- erp5/trunk/products/ZSQLCatalog/tests/testSQLCatalog.py [utf8] (original)
+++ erp5/trunk/products/ZSQLCatalog/tests/testSQLCatalog.py [utf8] Tue Apr 20 14:58:10 2010
@@ -217,8 +217,8 @@
'Query: %r\nSearchText: %r\nReference: %r\nSecond rendering: %r' % \
(query, search_text, reference_param_dict, search_text_param_dict))
- def asSQLExpression(self, kw):
- entire_query = self._catalog.buildEntireQuery(kw)
+ def asSQLExpression(self, kw, **build_entire_query_kw):
+ entire_query = self._catalog.buildEntireQuery(kw, **build_entire_query_kw)
return entire_query.asSQLExpression(self._catalog, False)
def _testDefaultKey(self, column):
@@ -549,6 +549,25 @@
select_dict = sql_expression.getSelectDict()
self.assertTrue('ambiguous_mapping' in select_dict, select_dict)
self.assertTrue('bar' in select_dict['ambiguous_mapping'], select_dict['ambiguous_mapping'])
+ # Doted alias: table name must get stripped. This is required to have an
+ # upgrade path from old ZSQLCatalog versions where pre-mapped columns were
+ # used in their select_expression. This must only happen in the
+ # "{column: None}" form, as otherwise it's the user explicitely asking for
+ # such alias (which is not strictly invalid).
+ sql_expression = self.asSQLExpression({'select_dict': {
+ 'foo.default': None,
+ 'foo.keyword': 'foo.keyword',
+ }}, query_table='foo')
+ select_dict = sql_expression.getSelectDict()
+ self.assertTrue('default' in select_dict, select_dict)
+ self.assertFalse('foo.default' in select_dict, select_dict)
+ self.assertTrue('foo.keyword' in select_dict, select_dict)
+ # Variant: same operation, but this time stripping generates an ambiguity.
+ # That must be detected and cause a mapping exception.
+ self.assertRaises(ValueError, self.asSQLExpression, {'select_dict': {
+ 'foo.ambiguous_mapping': None,
+ 'bar.ambiguous_mapping': None,
+ }}, query_table='foo')
def test_hasColumn(self):
self.assertTrue(self._catalog.hasColumn('uid'))
More information about the Erp5-report
mailing list