bprinty / Flask-Continuum

Model provenance and versioning via SQLAlchemy-Continuum
https://flask-continuum.readthedocs.io/en/latest/
MIT License
6 stars 3 forks source link

Setting up the flask application with extensions Python 3.10.6 Issue #14

Open ahmedozmaan opened 1 year ago

ahmedozmaan commented 1 year ago
from flask import Flask
from flask_sqlalchemy import SQLAlchemy
from flask_continuum import Continuum, VersioningMixin

app = Flask(__name__)
app.config['SQLALCHEMY_DATABASE_URI'] = 'sqlite:////tmp/test.db'

db = SQLAlchemy()
continuum = Continuum()

def create_app():
    db.init_app(app)
    continuum.init_app(app, db)
    return app

class Article(db.Model, VersioningMixin):
    __tablename__ = 'article'
    id = db.Column(db.Integer, primary_key=True, autoincrement=True)
    name = db.Column(db.Unicode(255))
    content = db.Column(db.UnicodeText)

if __name__ == '__main__':
    app = create_app()
    app.run()

# my env set up
# Flask==2.2.3
# Flask-Continuum==0.1.7
# Flask-SQLAlchemy==3.0.3
#
# Python 3.10.6
# OS Ubuntu 22.04.2 LTS

### when I run the app it rises this issue

Traceback (most recent call last): File "/home/me/project/app.py", line 18, in app = create_app() File "/home/me/project/app.py", line 14, in create_app continuum.init_app(app, db) File "/home/me/project/venv/lib/python3.10/site-packages/flask_continuum/plugin.py", line 168, in init_app if db.app is None: File "/home/me/project/venv/lib/python3.10/site-packages/flask_sqlalchemy/extension.py", line 1005, in getattr raise AttributeError(name) AttributeError: app

adorsett commented 1 year ago

I'm getting the same error when using this method from the documentation:

app = Flask(__name__)
db = SQLAlchemy(app)
continuum = Continuum(app, db)