• Home
  • Features
  • Pricing
  • Docs
  • Announcements
  • Sign In

noirbizarre / flask-restplus / 793
38%

Build:
DEFAULT BRANCH: master
Ran 12 Sep 2019 03:10PM UTC
Jobs 8
Files 20
Run time 10min
Badge
Embed ▾
README BADGES
x

If you need to use a raster PNG badge, change the '.svg' to '.png' in the link

Markdown

Textile

RDoc

HTML

Rst

pending completion
793

push

travis-ci

SteadBytes
Fix ambiguity error with Polymorphism candidates (isinstance() problem) (#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

1 of 1 new or added line in 1 file covered. (100.0%)

2536 of 2617 relevant lines covered (96.9%)

7.73 hits per line

Jobs
ID Job ID Ran Files Coverage
1 793.1 12 Sep 2019 03:10PM UTC 0
96.76
Travis Job 793.1
2 793.2 12 Sep 2019 03:11PM UTC 0
96.54
Travis Job 793.2
3 793.3 12 Sep 2019 03:11PM UTC 0
96.57
Travis Job 793.3
4 793.4 12 Sep 2019 03:11PM UTC 0
96.57
Travis Job 793.4
5 793.5 12 Sep 2019 03:12PM UTC 0
96.57
Travis Job 793.5
6 793.6 12 Sep 2019 03:15PM UTC 0
96.8
Travis Job 793.6
7 793.7 12 Sep 2019 03:15PM UTC 0
96.53
Travis Job 793.7
8 793.8 12 Sep 2019 03:13PM UTC 0
96.58
Travis Job 793.8
Source Files on build 793
Detailed source file information is not available for this build.
  • Back to Repo
  • Travis Build #793
  • a7e363a8 on github
  • Prev Build on master (#789)
  • Next Build on master (#807)
STATUS · Troubleshooting · Open an Issue · Sales · Support · CAREERS · ENTERPRISE · START FREE · SCHEDULE DEMO
ANNOUNCEMENTS · TWITTER · TOS & SLA · Supported CI Services · What's a CI service? · Automated Testing

© 2025 Coveralls, Inc