diff --git a/product/ZSQLCatalog/Extensions/zsqlbrain.py b/product/ZSQLCatalog/Extensions/zsqlbrain.py index 81427eed4565454bac40bbf89af6339e11f86655..e1ad611470998f75dd71e47e39b6ae1f04a6dc76 100644 --- a/product/ZSQLCatalog/Extensions/zsqlbrain.py +++ b/product/ZSQLCatalog/Extensions/zsqlbrain.py @@ -15,26 +15,27 @@ import string import Acquisition import sys +import traceback from ZODB.POSException import ConflictError from AccessControl import ClassSecurityInfo from AccessControl.SecurityInfo import allow_class -from zLOG import LOG +from zLOG import LOG, WARNING _MARKER = [] -class ZSQLBrain(Acquisition.Implicit): +class ZSQLBrain(Acquisition.Implicit): security = ClassSecurityInfo() security.declareObjectPublic() def _aq_dynamic(self, name): - """Acquire an attribute from a real object. - """ - if name.startswith('__') : - return None - o = self.getObject() - return getattr(o, name, None) + """Acquire an attribute from a real object. + """ + if name.startswith('__') : + return None + o = self.getObject() + return getattr(o, name, None) def getURL(self): return self.path @@ -120,3 +121,38 @@ class ZSQLBrain(Acquisition.Implicit): pass allow_class(ZSQLBrain) + +class ZSQLBrainNoObject(ZSQLBrain): + security = ClassSecurityInfo() + security.declareObjectPublic() + + def getObject(self): + stack = ''.join(traceback.format_stack()) + LOG('Products.ZSQLCatalog.Extentions.zsqlbrain.ZSQLBrainNoObject', WARNING, + "Attempted direct access to object %r:\n%s" % (self.getPath(), stack)) + return None + + def getProperty(self, name, d=_MARKER, **kw): + value = None + if hasattr(self, name): + value = getattr(self, name) + else: + stack = ''.join(traceback.format_stack()) + LOG('Products.ZSQLCatalog.Extentions.zsqlbrain.ZSQLBrainNoObject', + WARNING, + "Non-existing property %r on record for %r:\n%s" % (name, + self.getPath(), + stack)) + return None + return value + + def _aq_dynamic(self, name): + """Do not acquire an attribute from a real object. + """ + stack = ''.join(traceback.format_stack(limit=5)) + LOG('Products.ZSQLCatalog.Extentions.zsqlbrain.ZSQLBrainNoObject', WARNING, + "Non-existing attribute %r on record for %r:\n%s" % (name, + self.getPath(), + stack)) +allow_class(ZSQLBrainNoObject) + diff --git a/product/ZSQLCatalog/SQLCatalog.py b/product/ZSQLCatalog/SQLCatalog.py index a2e0d8c82409a57de600b4d4cd8c70fa7d277fb1..549a0cba63a030caad9665667b82d85d59d47c69 100644 --- a/product/ZSQLCatalog/SQLCatalog.py +++ b/product/ZSQLCatalog/SQLCatalog.py @@ -2354,6 +2354,12 @@ class Catalog(Folder, """ return getComparisonOperatorInstance(operator) + PROPAGATE_PARAMETER_SET = set(['selection_domain', + 'selection_report', + # XXX should get the next parameters from + # the ZSQLMethod class itself + 'zsql_brain', + ]) @profiler_decorator def _queryResults(self, REQUEST=None, build_sql_query_method=None, **kw): """ Returns a list of brains from a set of constraints on variables """ @@ -2363,11 +2369,10 @@ class Catalog(Folder, # XXX: decide if this should be made normal ENFORCE_SEPARATION = True if ENFORCE_SEPARATION: - new_kw = {} # Some parameters must be propagated: - for parameter_id in ('selection_domain', 'selection_report'): - if parameter_id in kw: - new_kw[parameter_id] = kw[parameter_id] + new_kw = dict((name, kw[name]) + for name in self.PROPAGATE_PARAMETER_SET & set(kw)) + # discard all others: kw = new_kw kw['where_expression'] = query['where_expression'] kw['sort_on'] = query['order_by_expression'] @@ -2376,6 +2381,7 @@ class Catalog(Folder, kw['limit_expression'] = query['limit_expression'] kw['select_expression'] = query['select_expression'] kw['group_by_expression'] = query['group_by_expression'] + # XXX: why not kw.update(query)?? return kw def queryResults(self, sql_method, REQUEST=None, src__=0, build_sql_query_method=None, **kw):