Commits

Jimmy Yuen Ho Wong committed 0b399e5

fixed bug where non-recursive to_collection from SA models returns non-sensical values

  • Participants
  • Parent commits a4428b1

Comments (0)

Files changed (1)

File src/blueberrypy/util.py

            "pad_block_cipher_message", "unpad_block_cipher_message"]
 
 
-def _get_model_properties(model, excludes):
+def _get_model_properties(model, excludes, recursive=False):
     props = {}
     for prop in model.__mapper__.iterate_properties:
         if isinstance(prop, RelationshipProperty):
-            props[prop.key] = prop
-            if prop.backref:
-                backref_prop_key = prop.backref[0]
-                for mapper in prop.mapper.polymorphic_iterator():
-                    excludes.setdefault(mapper.class_, set()).add(backref_prop_key)
+            if recursive:
+                props[prop.key] = prop
+                if prop.backref:
+                    backref_prop_key = prop.backref[0]
+                    for mapper in prop.mapper.polymorphic_iterator():
+                        excludes.setdefault(mapper.class_, set()).add(backref_prop_key)
         else:
             if prop.key.startswith("_"):
                 props[prop.columns[0].key] = prop
         includes = _ensure_is_dict(from_.__class__, includes)
         excludes = _ensure_is_dict(from_.__class__, excludes)
 
-        props = _get_model_properties(from_, excludes)
+        props = _get_model_properties(from_, excludes, recursive=recursive)
         attrs = set(props.iterkeys())
         if includes and from_.__class__ in includes:
             attrs |= includes[from_.__class__]