before we expose a sqlalchemy object to the xmlrpc wire, we need to
authorThierry Parmentelat <thierry.parmentelat@inria.fr>
Tue, 25 Sep 2012 14:24:18 +0000 (16:24 +0200)
committerThierry Parmentelat <thierry.parmentelat@inria.fr>
Tue, 25 Sep 2012 14:24:18 +0000 (16:24 +0200)
clean up related objects - xmlrpc would not allow it, we expose hrns
instead anyways
the way we did this before this change was to look for lists of
RegRecord or RegKey
however it turns out the lists are actually instances of
sqlalchemy.orm.collections.InstrumentedList
so if a list turns out empty, it did not get filter out but could not
get marshalled either
we simplify the code for filtering out (Record.todict) to exclude
objects only on the value type (not its sons when it's a list)
and the manager does not pass RegRecord or RegKey anymore, but just
InstrmentedList

sfa/managers/registry_manager.py
sfa/storage/record.py

index b5a63a9..564fb44 100644 (file)
@@ -20,6 +20,9 @@ from sfa.trust.gid import create_uuid
 from sfa.storage.model import make_record, RegRecord, RegAuthority, RegUser, RegSlice, RegKey, \
     augment_with_sfa_builtins
 from sfa.storage.alchemy import dbsession
+### the types that we need to exclude from sqlobjects before being able to dump
+# them on the xmlrpc wire
+from sqlalchemy.orm.collections import InstrumentedList
 
 class RegistryManager:
 
@@ -179,7 +182,7 @@ class RegistryManager:
         # xxx somehow here calling dict(record) issues a weird error
         # however record.todict() seems to work fine
         # records.extend( [ dict(record) for record in local_records ] )
-        records.extend( [ record.todict(exclude_types=[RegRecord,RegKey]) for record in local_records ] )
+        records.extend( [ record.todict(exclude_types=[InstrumentedList]) for record in local_records ] )
 
         if not records:
             raise RecordNotFound(str(hrns))
@@ -228,7 +231,7 @@ class RegistryManager:
                 records = dbsession.query(RegRecord).filter_by(authority=hrn)
             # 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=[RegRecord,RegKey]) for record in records ]
+            record_dicts=[ record.todict(exclude_types=[InstrumentedList]) for record in records ]
     
         return record_dicts
     
index 1aa3aa9..812efde 100644 (file)
@@ -33,7 +33,8 @@ class Record:
         # fallback
         return "** undef_datetime **"
     
-    # it may be important to exclude relationships
+    # it may be important to exclude relationships, which fortunately
+    # 
     def todict (self, exclude_types=[]):
         d=self.__dict__
         def exclude (k,v):
@@ -41,7 +42,6 @@ class Record:
             if exclude_types:
                 for exclude_type in exclude_types:
                     if isinstance (v,exclude_type): return True
-                    if isinstance (v,list) and v and isinstance (v[0],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 ] )