Skip to content

Commit

Permalink
fixed reporting on undefined list attributes
Browse files Browse the repository at this point in the history
  • Loading branch information
wouterdb committed Jun 26, 2018
1 parent 1efc7e9 commit fcfe556
Show file tree
Hide file tree
Showing 3 changed files with 19 additions and 2 deletions.
2 changes: 1 addition & 1 deletion src/inmanta/ast/attribute.py
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,6 @@
from inmanta.execute.util import Unknown
from typing import List


try:
from typing import TYPE_CHECKING
except ImportError:
Expand All @@ -49,6 +48,7 @@ def __init__(self, entity: "Entity", value_type: "Type", name: str, multi: bool=
self.__type = value_type
self.__multi = multi
self.__nullallble = nullable
self.low = 0 if nullable else 1
self.comment = None # type: str

def get_type(self) -> "Type":
Expand Down
4 changes: 3 additions & 1 deletion src/inmanta/execute/runtime.py
Original file line number Diff line number Diff line change
Expand Up @@ -658,7 +658,9 @@ def final(self, excns):
attr = self.type.get_attribute(k)
if attr.is_multi():
low = attr.low
length = len(v.value)
# none for list attributes
# list for n-ary relations
length = 0 if v.value is None else len(v.value)
excns.append(UnsetException(
"The object %s is not complete: attribute %s (%s) requires %d values but only %d are set" %
(self, k, attr.location, low, length), self, attr))
Expand Down
15 changes: 15 additions & 0 deletions tests/test_compiler_errors.py
Original file line number Diff line number Diff line change
Expand Up @@ -382,3 +382,18 @@ def test_610_multi_add(snippetcompiler):
""",
"The object __config__::A (instantiated at {dir}/main.cf:13) is not complete:"
" attribute b ({dir}/main.cf:11:11) requires 2 values but only 1 are set")


def test_653_list_attribute_unset(snippetcompiler):
snippetcompiler.setup_for_error(
"""
entity Test:
string[] bla
end
Test()
implement Test using std::none
""",
"The object __config__::Test (instantiated at {dir}/main.cf:6) is not complete:"
" attribute bla ({dir}/main.cf:3) requires 1 values but only 0 are set")

0 comments on commit fcfe556

Please sign in to comment.