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

chore: support sqlalchemy 2.x and flask-sqlalchemy 3 (breaking) #2241

Open
wants to merge 30 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
30 commits
Select commit Hold shift + click to select a range
52e603f
chore: support sqlalchemy 2.x and flask-sqlalchemy 3
dpgaspar May 16, 2024
cce3b59
quickhowto working
dpgaspar May 16, 2024
581d7cf
examples
dpgaspar May 17, 2024
494f00e
breaking changes and type annotations
dpgaspar May 20, 2024
04b92f9
breaking changes on messages and exceptions on CRUD interface
dpgaspar May 28, 2024
eb513d3
fix tests part1
dpgaspar May 28, 2024
f88356e
Merge branch 'master' into danielgaspar/sc-80567/bump-fab-to-sqlalche…
dpgaspar May 28, 2024
7605717
fix lint
dpgaspar May 28, 2024
b6a7225
fix tests part 2
dpgaspar May 29, 2024
e1f321a
fix tests part 3
dpgaspar May 31, 2024
4bebf80
fix tests part 4
dpgaspar May 31, 2024
b81d10f
fix tests part 5
dpgaspar May 31, 2024
870282d
fix tests part 6
dpgaspar May 31, 2024
52611cc
fix tests part 7
dpgaspar May 31, 2024
82df156
fix tests part 8
dpgaspar May 31, 2024
2d358c0
fix tests part 9
dpgaspar May 31, 2024
2da0c0e
fix tests part 10
dpgaspar May 31, 2024
d99394e
fix tests part 11
dpgaspar May 31, 2024
5f1b0bc
fix for mssql
dpgaspar May 31, 2024
8637242
deprecate and simplify stuff
dpgaspar Jun 3, 2024
44b8a5c
fix tests
dpgaspar Jun 3, 2024
ec7ecaa
fix tests
dpgaspar Jun 3, 2024
9b19585
remove OID and mongodb from tests
dpgaspar Jun 4, 2024
83d43af
Revert "remove OID and mongodb from tests"
dpgaspar Jun 4, 2024
ce63d11
remove support for OpenID and MongoDB
dpgaspar Jun 4, 2024
dbe567b
fix lint
dpgaspar Jun 4, 2024
9d5027f
fix examples part1
dpgaspar Jun 4, 2024
b49bd34
fix examples part2, make extending user possible
dpgaspar Jun 4, 2024
fba2a39
fix don't init flask-sqlalchemy if it's already inited
dpgaspar Jun 5, 2024
6c45a08
fix m-m relation with m-o with doted notation
dpgaspar Jun 6, 2024
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
61 changes: 1 addition & 60 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ jobs:
- name: flake8
run: flake8 flask_appbuilder
- name: mypy
run: mypy flask_appbuilder
run: mypy flask_appbuilder/**/*.py
- name: black
run: black --check tests
- name: flake8
Expand Down Expand Up @@ -187,62 +187,3 @@ jobs:
- name: Upload code coverage
run: |
bash <(curl -s https://codecov.io/bash) -cF python

test-mongodb:
runs-on: ubuntu-22.04
strategy:
matrix:
python-version: [3.8]
services:
mongo:
image: mongo:4.4.1-bionic
ports:
- 27017:27017
steps:
- uses: actions/checkout@v4
- name: Setup Python
uses: actions/setup-python@v5
with:
python-version: ${{ matrix.python-version }}
- name: Install dependencies
run: |
sudo apt-get update
sudo apt-get install -y libldap2-dev libsasl2-dev libssl-dev
pip install --upgrade pip
pip install -r requirements/base.txt
pip install -r requirements/tests.txt
pip install -r requirements/extra.txt
pip install -r requirements/mongodb.txt
- name: Run tests
run: |
nose2 -c setup.cfg -F -v --with-coverage --coverage flask_appbuilder -A 'mongo' tests
- name: Upload code coverage
run: |
bash <(curl -s https://codecov.io/bash) -cF python

test-openid:
runs-on: ubuntu-22.04
strategy:
matrix:
python-version: [3.8]
steps:
- uses: actions/checkout@v4
- name: Setup Python
uses: actions/setup-python@v5
with:
python-version: ${{ matrix.python-version }}
- name: Install dependencies
run: |
sudo apt-get update
sudo apt-get install -y libldap2-dev libsasl2-dev libssl-dev
pip install --upgrade pip
pip install -r requirements/base.txt
pip install -r requirements/tests.txt
pip install -r requirements/extra.txt
pip install -r requirements/openid.txt
- name: Run tests
run: |
nose2 -c setup.cfg -F -v --with-coverage --coverage flask_appbuilder -A 'openid' tests
- name: Upload code coverage
run: |
bash <(curl -s https://codecov.io/bash) -cF python
File renamed without changes.
528 changes: 209 additions & 319 deletions docs/config.rst

Large diffs are not rendered by default.

1 change: 0 additions & 1 deletion examples/base_api/README.rst
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@ Simple example showing how to use *BaseApi* class

Run it::

$ export FLASK_APP=app/__init__.py
$ flask run

For Swagger view go to: http://localhost:5000/swagger/v1
24 changes: 9 additions & 15 deletions examples/base_api/app/__init__.py
Original file line number Diff line number Diff line change
@@ -1,19 +1,13 @@
import logging

from flask import Flask
from flask_appbuilder import AppBuilder, SQLA

"""
Logging configuration
"""
logging.basicConfig(format="%(asctime)s:%(levelname)s:%(name)s:%(message)s")
logging.getLogger().setLevel(logging.DEBUG)


app = Flask(__name__)
app.config.from_object("config")
db = SQLA(app)
appbuilder = AppBuilder(app, db.session)
from .api import ExampleApi
from .extensions import appbuilder


from . import api # noqa
def create_app() -> Flask:
app = Flask(__name__)
app.config.from_object("config")
with app.app_context():
appbuilder.init_app(app)
appbuilder.add_api(ExampleApi)
return app
18 changes: 11 additions & 7 deletions examples/base_api/app/api.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,13 +2,15 @@
from flask_appbuilder.api import BaseApi, expose, rison, safe
from flask_appbuilder.security.decorators import protect

from . import appbuilder

greeting_schema = {"type": "object", "properties": {"name": {"type": "string"}}}
greeting_schema = {
"type": "object",
"properties": {"name": {"type": "string"}},
"required": ["name"],
}


class ExampleApi(BaseApi):

resource_name = "example"
apispec_parameter_schemas = {"greeting_schema": greeting_schema}

Expand Down Expand Up @@ -77,7 +79,12 @@ def greeting4(self, **kwargs):
---
get:
parameters:
- $ref: '#/components/parameters/greeting_schema'
- in: query
name: q
content:
application/json:
schema:
$ref: '#/components/schemas/greeting_schema'
responses:
200:
description: Greet the user
Expand Down Expand Up @@ -137,6 +144,3 @@ def error(self):
$ref: '#/components/responses/500'
"""
raise Exception


appbuilder.add_api(ExampleApi)
4 changes: 4 additions & 0 deletions examples/base_api/app/extensions.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
from flask_appbuilder import AppBuilder


appbuilder = AppBuilder()
43 changes: 0 additions & 43 deletions examples/base_api/config.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,55 +5,12 @@
CSRF_ENABLED = True
SECRET_KEY = "\2\1thisismyscretkey\1\2\e\y\y\h"

OPENID_PROVIDERS = [
{"name": "Google", "url": "https://www.google.com/accounts/o8/id"},
{"name": "Yahoo", "url": "https://me.yahoo.com"},
{"name": "AOL", "url": "http://openid.aol.com/<username>"},
{"name": "Flickr", "url": "http://www.flickr.com/<username>"},
{"name": "MyOpenID", "url": "https://www.myopenid.com"},
]

SQLALCHEMY_DATABASE_URI = "sqlite:///" + os.path.join(basedir, "app.db")
# SQLALCHEMY_DATABASE_URI = 'mysql://myapp@localhost/myapp'
# SQLALCHEMY_DATABASE_URI = 'postgresql://root:password@localhost/myapp'
BABEL_DEFAULT_LOCALE = "en"


# ------------------------------
# GLOBALS FOR APP Builder
# ------------------------------
FAB_API_SWAGGER_UI = True

BABEL_DEFAULT_LOCALE = "en"
BABEL_DEFAULT_FOLDER = "translations"
LANGUAGES = {
"en": {"flag": "gb", "name": "English"},
"pt": {"flag": "pt", "name": "Portuguese"},
"es": {"flag": "es", "name": "Spanish"},
"de": {"flag": "de", "name": "German"},
"zh": {"flag": "cn", "name": "Chinese"},
"ru": {"flag": "ru", "name": "Russian"},
}


UPLOAD_FOLDER = basedir + "/app/static/uploads/"
IMG_UPLOAD_FOLDER = basedir + "/app/static/uploads/"
IMG_UPLOAD_URL = "/static/uploads/"
AUTH_TYPE = 1
AUTH_ROLE_ADMIN = "Admin"
AUTH_ROLE_PUBLIC = "Public"
# APP_NAME = "My App Name"
# APP_ICON = "static/img/logo.jpg"
APP_THEME = "" # default
# APP_THEME = "cerulean.css"
# APP_THEME = "amelia.css"
# APP_THEME = "cosmo.css"
# APP_THEME = "cyborg.css"
# APP_THEME = "flatly.css"
# APP_THEME = "journal.css"
# APP_THEME = "readable.css"
# APP_THEME = "simplex.css"
# APP_THEME = "slate.css"
# APP_THEME = "spacelab.css"
# APP_THEME = "united.css"
# APP_THEME = "yeti.css"
Loading
Loading