Skip to content

Commit

Permalink
Issue #2786, compiler does not test arrayness of instance property va…
Browse files Browse the repository at this point in the history
…lues

The MOF compiler completely ignores issues of mismatch between the class
definition of properties arrayness and the corresponding values in
instances of the class. Thus, the compiler where a class with an array
property is defined will accept a single value property value (and
output it as a single value property value) and will accept an array
value defintion for an instance and produce an array value in the
CIMProperty.  This fix tests for this mismatch in the compiler and
generates an error if found.
  • Loading branch information
KSchopmeyer authored and andy-maier committed Nov 9, 2021
1 parent 1024bcc commit 9253324
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 2 deletions.
4 changes: 4 additions & 0 deletions docs/changes.rst
Original file line number Diff line number Diff line change
Expand Up @@ -126,6 +126,10 @@ Released: not yet
use mock versions of _imethodcall and _methodcall and simply duck typed
the methods. (see issue #2755)

* Fixes MOF compiler issue where the compiler was allowing array properties
to have corresponding instances instantiated with non-array values and
vice-versa. This now causes a parse error. (See issue # 2786)

* Docs: Fixed an error with the autodocsumm and Sphinx 4.0.0. (issue #2697)

* Jupyter Notebook: Ignored safety issues 40380..40386 in order to continue
Expand Down
17 changes: 15 additions & 2 deletions pywbem/_mof_compiler.py
Original file line number Diff line number Diff line change
Expand Up @@ -1876,7 +1876,7 @@ def p_instanceDeclaration(p):
in allowed_types])
raise MOFParseError(
msg=_format(
"Property {0|A} with value {1|A} embedded "
"Property {0!A} with value {1!A} embedded "
"object type must be ((1}). Actual type "
"is {2}", cprop.name, cls_names, type(obj)))
# If the compile produces no objects there must have
Expand All @@ -1885,14 +1885,27 @@ def p_instanceDeclaration(p):
if not objs:
raise MOFParseError(
msg=_format(
"Property {0|A} with value {1|A} embedded"
"Property {0!A} with value {1!A} embedded"
" object compile produced no instances.",
cprop.name, pval))

# If array type insert list, else insert item 0 from list
pprop.value = objs if cprop.is_array else objs[0]
pprop.embedded_object = embedded_object_type
else:
if pval:
ival_is_array = isinstance(pval, list)
if cprop.is_array != ival_is_array:
raise MOFParseError(
msg=_format(
"Property {0!A} value {1!A} in instance of "
"class {2!A} has class and instance array "
"mismatch. The class definition is "
"array={3} instance value type is array={4} "
"for value type {5}",
pname, pval, cc.classname, cprop.is_array,
ival_is_array, type(pval)),
parser_token=p)
pprop.value = cimvalue(pval, cprop.type)
inst.properties[pname] = pprop
except ValueError as ve:
Expand Down

0 comments on commit 9253324

Please sign in to comment.