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

Support Flask-SQLAlchemy 3.1 and SQLAlchemy 2 #195

Open
wants to merge 5 commits into
base: develop
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
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
7 changes: 6 additions & 1 deletion Changelog
Original file line number Diff line number Diff line change
@@ -1,3 +1,8 @@
2024-01-31
* Drop support for SQLALchemy 1.1, 1.2 and 1.3
* Add support for SQLALchemy >=2.0
* Add support for Flask-SQLAlchemy >=3.1

2022-03-23
* Django: Support for UUIDField

Expand Down Expand Up @@ -174,7 +179,7 @@
# No errors will be raised
user = mixer.blend('auth.User', username='mike')
null = mixer.blend('auth.User', username='mike')


2014-01-03 horneds

Expand Down
2 changes: 1 addition & 1 deletion mixer/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@
# Module information
# ==================

__version__ = "7.2.2"
__version__ = "7.3.0"
__project__ = "mixer"
__author__ = "horneds <[email protected]>"
__license__ = "BSD"
6 changes: 5 additions & 1 deletion mixer/backend/flask.py
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,11 @@ def init_app(self, app):
"""
assert app.extensions and app.extensions[
'sqlalchemy'], "Flask-SQLAlchemy must be inialized before Mixer."
db = app.extensions['sqlalchemy'].db
try:
db = app.extensions['sqlalchemy'].db
except AttributeError:
# https://github.com/pallets-eco/flask-sqlalchemy/issues/698#issuecomment-1250351168
db = app.extensions['sqlalchemy']
self.params['session'] = db.session

# register extension with app
Expand Down
2 changes: 1 addition & 1 deletion requirements-tests.txt
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
Django >= 3.0
Flask >= 1.0
Marshmallow >= 3.9
SQLAlchemy >= 1.1.4
SQLAlchemy >= 1.4
flask-sqlalchemy >= 2.1
mongoengine >= 0.10.1
peewee >= 3.7.0
Expand Down
7 changes: 3 additions & 4 deletions tests/test_sqlalchemy.py
Original file line number Diff line number Diff line change
Expand Up @@ -18,8 +18,7 @@
)
from sqlalchemy.dialects import mssql, mysql, oracle, postgresql, sqlite
from sqlalchemy.ext.declarative import declarative_base
from sqlalchemy.orm import relation, relationship, scoped_session, sessionmaker
from sqlalchemy.util import text_type
from sqlalchemy.orm import relationship, scoped_session, sessionmaker

ENGINE = create_engine('sqlite:///:memory:')
BASE = declarative_base()
Expand Down Expand Up @@ -71,7 +70,7 @@ class Role(BASE):
name = Column(String(20), primary_key=True)
user_id = Column(Integer, ForeignKey(User.id), nullable=False)

user = relation(User)
user = relationship(User)


BASE.metadata.create_all(ENGINE)
Expand Down Expand Up @@ -245,4 +244,4 @@ class Test(base):
def test_random_compiled(dialect, expected):
from mixer.backend.sqlalchemy import random
compiled = random().compile(dialect=dialect)
assert text_type(compiled) == expected
assert str(compiled) == expected