Commit 22bb14a3 authored by Sylvain Thénault's avatar Sylvain Thénault
Browse files

[entity creation] ensure this is a relation and not an attribute before moving...

[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)

--HG--
branch : stable
parent 589801acf08e
...@@ -261,8 +261,16 @@ class Entity(AppObject): ...@@ -261,8 +261,16 @@ class Entity(AppObject):
relations = [] relations = []
restrictions = set() restrictions = set()
pending_relations = [] pending_relations = []
eschema = cls.e_schema
for attr, value in kwargs.items(): 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: if len(value) == 1:
value = iter(value).next() value = iter(value).next()
else: else:
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment