Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Fix ambiguity error with Polymorphism candidates (isinstance() proble…
…m) (#691) * Fix for better Polymorphism support Right now Polymorphism fails when using something like this (models in sqlalchemy): models: ```python class Product(BaseModel): discr = Column(String) __mapper_args__ = { 'polymorphic_on': discr, 'polymorphic_identity': "product" } class VegetableProduct(Product): name = Column(String) __mapper_args__ = { 'polymorphic_identity': "vegetable" } class DairyProduct(VegetableProduct): __mapper_args__ = { 'polymorphic_identity': "dairy" } ``` mapper: ```python resource_product = api.model("Product", { 'discr': fields.String }) product_mapper = { VegetableProduct: api.inherit("Vegetable", resource_product, { 'name': fields.String }), DairyProduct: api.inherit("Dairy", resource_product, { 'name': fields.String }), } resource_result = api.model("ResourceResult", { 'products': fields.List(fields.Polymorphism(product_mapper)) }) ``` This sparkles error here: https://github.com/noirbizarre/flask-restplus/blob/master/flask_restplus/fields.py#L682 Because candidates will be: VegetableProduct and DairyProduct, since isinstance() will return True for both classes (I personally surprised it works like this) Checking by __class__.__name__ removes this error and it works as intended. I hope my quick fix did not break anything, I'm eager to update it if I don't know, more elegant solution is needed. * adjusted ambiguity test for new feature * stricter check for type * changed to simple class check * type() check for Polymorphism, adjusted tests * type() check for Polymorphism, adjusted tests * removed local dev files * updated test name, also PR in docblock
- Loading branch information