Mixer for my flask app gives error when used with db.init_app() -- AttributeError: 'module' object has no attribute 'extensions'
- Dominant language
- Python
- Stars
- 953
- Forks
- 91
- PR merge metrics
- No merged PRs in 30d
Description
Hi,
I am trying to use `mixer` with my flask app to create fake data. I have written below mixer module
```
# module: my-mixer.py
from flask import Flask
from mixer.backend.flask import mixer
from faker import Faker
from database import db
from models import Country
from recruitment import app
app = flask.Flask('myapp')
db.init_app(app)
db.app = app
fake = Faker()
mixer.init_app(app)
# Generate a random country
country = mixer.blend(Country)
# Generate a Country. Set country name.
country = mixer.blend(Country, country__name=fake.country())
```
The db is taken from
```
from flask.ext.sqlalchemy import SQLAlchemy
# no app object passed! Instead we use use db.init_app in the factory.
db = SQLAlchemy()
```
You can see that I am not directly binding app with db
```
db = SQLAlchemy(app)
```
Now when I run **my-mixer.py**, I get below error
```
Traceback (most recent call last):
File "faker-mixer.py", line 16, in
mixer.init_app(app)
File "/home/hussain/workspace/test/venv/local/lib/python2.7/site-packages/mixer/backend/flask.py", line 45, in init_app
assert app.extensions and app.extensions[
AttributeError: 'module' object has no attribute 'extensions'
```
##
Want to back this issue? **[Post a bounty on it!](https://www.bountysource.com/issues/16166740-mixer-for-my-flask-app-gives-error-when-used-with-db-init_app-attributeerror-module-object-has-no-attribute-extensions?utm_campaign=plugin&utm_content=tracker%2F327725&utm_medium=issues&utm_source=github)** We accept bounties via [Bountysource](https://www.bountysource.com/?utm_campaign=plugin&utm_content=tracker%2F327725&utm_medium=issues&utm_source=github).
Contributor guide
No contributing guide indexed for this repository
Research direction
Reproduce the failure by running my-mixer.py with the db defined in database and initialized through db.init_app(app). Start at mixer/backend/flask.py line 45 and compare that expectation with the Flask app setup shown in the issue. Done means the example no longer raises the AttributeError and the db.init_app() configuration remains supported.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- flask, python, sqlalchemy
- Domain
- backend, testing
- Issue type
- Bug
- Difficulty
- 3/5
- Estimated time
- 1-2 days
- Activity status
- Stale
- Clarity
- Needs clarification
- Newbie friendliness
- 45/100