Skip to content

Commit

Permalink
Added check for self referencing (#184), check for YList assignment.
Browse files Browse the repository at this point in the history
  • Loading branch information
psykokwak4 committed Jul 20, 2016
1 parent 9c25780 commit 780dafd
Showing 1 changed file with 14 additions and 4 deletions.
18 changes: 14 additions & 4 deletions sdk/python/ydk/services/meta_service.py
Original file line number Diff line number Diff line change
Expand Up @@ -105,7 +105,12 @@ def set_parent_imeta(entity, child_meta=None):
elif entity:
entity.i_meta = entity._meta_info()
if hasattr(entity, 'parent'):
set_parent_imeta(entity.parent, entity.i_meta)
if entity.parent is entity:
err_msg = ("YDK object is not created correctly,"
"parent pointer should not point to itself.")
raise YPYServiceError(error_msg=err_msg)
else:
set_parent_imeta(entity.parent, entity.i_meta)

def get_active_deviation_module_names(capabilities, entity):
""" Return active deviation module names """
Expand Down Expand Up @@ -175,7 +180,7 @@ def modify_member_meta(full_name, deviation_table, member):

def inject_imeta_helper(entity, deviation_table, parent=None):
""" Inject i_meta field to entity """
# leaflist could be a lsit a primitive types
# leaflist could be a list of primitive types
if isinstance(entity, YListItem):
entity = entity.item
if not hasattr(entity, '_meta_info'):
Expand Down Expand Up @@ -220,8 +225,13 @@ def inject_imeta_helper(entity, deviation_table, parent=None):
elif isinstance(value, READ) or isinstance(value, DELETE):
continue
elif member.mtype == REFERENCE_LIST:
for v in value:
inject_imeta_helper(v, deviation_table, entity.i_meta)
try:
for v in value:
inject_imeta_helper(v, deviation_table, entity.i_meta)
except TypeError:
raise YPYModelError("Assigned object to YList {},"
" use list method instead."
.format(entity.i_meta.name))
elif member.mtype in (REFERENCE_CLASS, ANYXML_CLASS):
inject_imeta_helper(value, deviation_table, entity.i_meta)

Expand Down

0 comments on commit 780dafd

Please sign in to comment.