[Python-experimental] Fix TypeError: unhashable type: 'list' (#5810)

* handle scenario when value is a list, fix TypeError: unhashable type: 'list'

* Add __hash__ function

* use list instead of set

* use list instead of set

* use list instead of set

* use list instead of set

* use list instead of set

* use list instead of set
This commit is contained in:
Sebastien Rosset
2020-04-15 17:02:56 -07:00
committed by GitHub
parent 827904f732
commit 91cfabdad2
3 changed files with 30 additions and 12 deletions

View File

@@ -41,11 +41,17 @@
if self._path_to_item:
path_to_item.extend(self._path_to_item)
path_to_item.append(name)
values = set()
values = []
# A composed model stores child (oneof/anyOf/allOf) models under
# self._var_name_to_model_instances. A named property can exist in
# multiple child models. If the property is present in more than one
# child model, the value must be the same across all the child models.
if model_instances:
for model_instance in model_instances:
if name in model_instance._data_store:
values.add(model_instance._data_store[name])
v = model_instance._data_store[name]
if v not in values:
values.append(v)
len_values = len(values)
if len_values == 0:
raise ApiKeyError(
@@ -53,10 +59,10 @@
path_to_item
)
elif len_values == 1:
return list(values)[0]
return values[0]
elif len_values > 1:
raise ApiValueError(
"Values stored for property {0} in {1} difffer when looking "
"Values stored for property {0} in {1} differ when looking "
"at self and self's composed instances. All values must be "
"the same".format(name, type(self).__name__),
path_to_item

View File

@@ -274,11 +274,17 @@ class ModelComposed(OpenApiModel):
if self._path_to_item:
path_to_item.extend(self._path_to_item)
path_to_item.append(name)
values = set()
values = []
# A composed model stores child (oneof/anyOf/allOf) models under
# self._var_name_to_model_instances. A named property can exist in
# multiple child models. If the property is present in more than one
# child model, the value must be the same across all the child models.
if model_instances:
for model_instance in model_instances:
if name in model_instance._data_store:
values.add(model_instance._data_store[name])
v = model_instance._data_store[name]
if v not in values:
values.append(v)
len_values = len(values)
if len_values == 0:
raise ApiKeyError(
@@ -286,10 +292,10 @@ class ModelComposed(OpenApiModel):
path_to_item
)
elif len_values == 1:
return list(values)[0]
return values[0]
elif len_values > 1:
raise ApiValueError(
"Values stored for property {0} in {1} difffer when looking "
"Values stored for property {0} in {1} differ when looking "
"at self and self's composed instances. All values must be "
"the same".format(name, type(self).__name__),
path_to_item

View File

@@ -274,11 +274,17 @@ class ModelComposed(OpenApiModel):
if self._path_to_item:
path_to_item.extend(self._path_to_item)
path_to_item.append(name)
values = set()
values = []
# A composed model stores child (oneof/anyOf/allOf) models under
# self._var_name_to_model_instances. A named property can exist in
# multiple child models. If the property is present in more than one
# child model, the value must be the same across all the child models.
if model_instances:
for model_instance in model_instances:
if name in model_instance._data_store:
values.add(model_instance._data_store[name])
v = model_instance._data_store[name]
if v not in values:
values.append(v)
len_values = len(values)
if len_values == 0:
raise ApiKeyError(
@@ -286,10 +292,10 @@ class ModelComposed(OpenApiModel):
path_to_item
)
elif len_values == 1:
return list(values)[0]
return values[0]
elif len_values > 1:
raise ApiValueError(
"Values stored for property {0} in {1} difffer when looking "
"Values stored for property {0} in {1} differ when looking "
"at self and self's composed instances. All values must be "
"the same".format(name, type(self).__name__),
path_to_item