From: Thierry Parmentelat Date: Fri, 5 Jun 2015 07:14:28 +0000 (+0200) Subject: add a useless print statement to work around a weird issue we have with sqlalchemy... X-Git-Tag: sfa-3.1-17~12 X-Git-Url: http://git.onelab.eu/?p=sfa.git;a=commitdiff_plain;h=597e216fce70183af63c50b99db2065cfa6e5e2d add a useless print statement to work around a weird issue we have with sqlalchemy objects and their __dict__ value being wrong this is the second occurrence of that issue and a better solution is clearly needed in the mix, record.todict() now expects a tuple of types to exclude; this way we can use isinstance natively --- diff --git a/sfa/managers/registry_manager.py b/sfa/managers/registry_manager.py index 52911256..6049ebbd 100644 --- a/sfa/managers/registry_manager.py +++ b/sfa/managers/registry_manager.py @@ -288,8 +288,15 @@ class RegistryManager: records = dbsession.query(RegRecord).filter_by(authority=hrn).all() # logger.debug("non recursive mode, found %d local records"%(len(records))) # so that sfi list can show more than plain names... - for record in records: augment_with_sfa_builtins (record) - record_dicts=[ record.todict(exclude_types=[InstrumentedList]) for record in records ] + for record in records: + # xxx mystery - again this useless statement is key here so that + # resulting records have their __dict__ field actually in line with the + # object's contents; was first observed with authorities' 'name' column + # that would be missing from result as received by client + # record.todict() is the place where __dict__ is used + print "DO NOT REMOVE ME before augment_with_sfa_builtins, record=%s"%record + augment_with_sfa_builtins(record) + record_dicts = [ record.todict(exclude_types=(InstrumentedList,)) for record in records ] return record_dicts @@ -486,7 +493,7 @@ class RegistryManager: record.email = email # update the PLC information that was specified with the record - # xxx oddly enough, without this useless statement, + # xxx mystery: oddly enough, without this useless statement, # record.__dict__ as received by the driver seems to be off # anyway the driver should receive an object # (and then extract __dict__ itself if needed) diff --git a/sfa/storage/record.py b/sfa/storage/record.py index 9fcab19f..a4a87b49 100644 --- a/sfa/storage/record.py +++ b/sfa/storage/record.py @@ -4,6 +4,8 @@ from datetime import datetime from sfa.util.xml import XML from sfa.trust.gid import GID +from sfa.util.sfalogging import logger + class Record: def __init__(self, dict=None, xml=None): @@ -33,19 +35,18 @@ class Record: # fallback return "** undef_datetime **" - # it may be important to exclude relationships, which fortunately + # + # need to filter out results, esp. wrt relationships + # exclude_types must be a tuple so we can use isinstance # def todict (self, exclude_types=None): - if exclude_types is None: exclude_types=[] - d=self.__dict__ - def exclude (k,v): - if k.startswith('_'): return True - if exclude_types: - for exclude_type in exclude_types: - if isinstance (v,exclude_type): return True - return False - keys=[k for (k,v) in d.items() if not exclude(k,v)] - return dict ( [ (k,d[k]) for k in keys ] ) + if exclude_types is None: + exclude_types = () + d = self.__dict__ + def exclude (k, v): + return k.startswith('_') or isinstance (v, exclude_types) + keys = [ k for k, v in d.items() if not exclude(k, v) ] + return { k : d[k] for k in keys } def toxml(self): return self.save_as_xml()