Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[BUG] [python-experimental] TypeError: Cannot create a consistent method resolution order (MRO) #11434

Closed
3 of 6 tasks
tnielens opened this issue Jan 28, 2022 · 2 comments · Fixed by #13358
Closed
3 of 6 tasks

Comments

@tnielens
Copy link

tnielens commented Jan 28, 2022

Bug Report Checklist

  • Have you provided a full/minimal spec to reproduce the issue?
  • Have you validated the input using an OpenAPI validator (example)?
  • Have you tested with the latest master to confirm the issue still exists?
  • Have you searched for related issues/PRs?
  • What's the actual output vs expected output?
    api call fails although I expect it to succeed
  • [Optional] Sponsorship to speed up the bug fix or feature request (example)
Description

python 3.10.1

TypeError                                 Traceback (most recent call last)
File ~/projects/openapi_client_eliabidmgr/api/energy_bid_api_endpoints/list_energy_bid_summary.py:271, in ListEnergyBidSummary.list_energy_bid_summary(self, query_params, header_params, accept_content_types, stream, timeout, skip_deserialization)
    269 response_for_status = _status_code_to_response.get(str(response.status))
    270 if response_for_status:
--> 271     api_response = response_for_status.deserialize(response, self.api_client.configuration)
    272 else:
    273     api_response = api_client.ApiResponseWithoutDeserialization(response=response)

File ~/projects/openapi_client_eliabidmgr/api_client.py:797, in OpenApiResponse.deserialize(self, response, configuration)
    795     body_schema = self.content[content_type].schema
    796     _instantiation_metadata = InstantiationMetadata(from_server=True, configuration=configuration)
--> 797     deserialized_body = body_schema._from_openapi_data(
    798         body_data, _instantiation_metadata=_instantiation_metadata)
    799 elif streamed:
    800     response.release_conn()

File ~/projects/openapi_client_eliabidmgr/schemas.py:1706, in ListSchema._from_openapi_data(cls, arg, _instantiation_metadata)
   1704 @classmethod
   1705 def _from_openapi_data(cls, arg: typing.List[typing.Any], _instantiation_metadata: typing.Optional[InstantiationMetadata] = None):
-> 1706     return super()._from_openapi_data(arg, _instantiation_metadata=_instantiation_metadata)

File ~/projects/openapi_client_eliabidmgr/schemas.py:1390, in Schema._from_openapi_data(cls, arg, _instantiation_metadata)
   1386 if not _instantiation_metadata.from_server:
   1387     raise ApiValueError(
   1388         'from_server must be True in this code path, if you need it to be False, use cls()'
   1389     )
-> 1390 new_cls = cls.__get_new_cls(arg, _instantiation_metadata)
   1391 new_inst = new_cls.__get_new_instance_without_conversion(arg, _instantiation_metadata)
   1392 return new_inst

File ~/projects/openapi_client_eliabidmgr/schemas.py:1321, in Schema.__get_new_cls(cls, arg, _instantiation_metadata)
   1319             chosen_schema_classes.remove(x_schema)
   1320     used_classes = tuple(sorted(chosen_schema_classes, key=lambda a_cls: a_cls.__name__)) + suffix
-> 1321     mfg_cls = get_new_class(class_name='DynamicSchema', bases=used_classes)
   1323 if inheritable_primitive_type and not enum_schema:
   1324     _instantiation_metadata.path_to_schemas[path] = mfg_cls

File ~/projects/openapi_client_eliabidmgr/schemas.py:2037, in get_new_class(class_name, bases)
   2029 @functools.cache
   2030 def get_new_class(
   2031     class_name: str,
   2032     bases: typing.Tuple[typing.Type[typing.Union[Schema, typing.Any]], ...]
   2033 ) -> typing.Type[Schema]:
   2034     """
   2035     Returns a new class that is made with the subclass bases
   2036     """
-> 2037     return type(class_name, bases, {})

TypeError: Cannot create a consistent method resolution
order (MRO) for bases AnyTypeSchema, DeliveryPoint, frozendict
openapi-generator version

git master 0bb08a7

OpenAPI declaration file content or url
Generation Details

openapi-generator-cli generate -g python-experimental -i <file>

Steps to reproduce

Api call fails at runtime. I can't disclose the api. I hope the stacktrace is sufficient to identify the issue.

@spacether
Copy link
Contributor

spacether commented Jan 30, 2022

The stack trace is not sufficient to replicate this issue and fix it. Can you please provide a simplified spec that demonstrates the problem to allow someone to fix this problem?

The reason one is unable to fix this problem is that the python interpreter is saying that the classes AnyTypeSchema, DeliveryPoint, frozendict conflict with eachother and have an inconsistent method resolution order. We as readers have no idea what the definition inside DeliveryPoint is, so we don't know what conflicts and what to fix.

@spacether
Copy link
Contributor

This is probably happening because DeliveryPoint is a subclass of AnyTypeSchema, so AnyTypeSchema must be removed if another class is a subclass of it.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
2 participants