[entity creation] ensure this is a relation and not an attribute before moving things into pending_relations because value is a list stable
authorSylvain Thénault <sylvain.thenault@logilab.fr>
Fri, 08 Apr 2011 09:02:55 +0200
branchstable
changeset 7200 81fd6e40a6a8
parent 7199 589801acf08e
child 7201 52f5831400b2
[entity creation] ensure this is a relation and not an attribute before moving things into pending_relations because value is a list Using a list for attributes may be used for later type specific casting (e.g. timeseries)
entity.py
--- a/entity.py	Thu Apr 07 18:10:07 2011 +0200
+++ b/entity.py	Fri Apr 08 09:02:55 2011 +0200
@@ -261,8 +261,16 @@
         relations = []
         restrictions = set()
         pending_relations = []
+        eschema = cls.e_schema
         for attr, value in kwargs.items():
-            if isinstance(value, (tuple, list, set, frozenset)):
+            if attr.startswith('reverse_'):
+                attr = attr[len('reverse_'):]
+                role = 'object'
+            else:
+                role = 'subject'
+            assert eschema.has_relation(attr, role)
+            rschema = eschema.subjrels[attr] if role == 'subject' else eschema.objrels[attr]
+            if not rschema.final and isinstance(value, (tuple, list, set, frozenset)):
                 if len(value) == 1:
                     value = iter(value).next()
                 else: