Skip to content
Merged
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
6 changes: 5 additions & 1 deletion .github/workflows/tests.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,11 @@ jobs:
- python: '3.12'
tox: 'py312-noflaskbabel'
- python: '3.12'
tox: 'py312-flaskmongoengine'
tox: 'py312-flaskmongoengine-sqlalchemy1'
- python: '3.8'
tox: 'py38-sqlalchemy1'
- python: '3.12'
tox: 'py312-sqlalchemy1'
services:
# Label used to access the service container
postgres:
Expand Down
2 changes: 1 addition & 1 deletion flask_admin/contrib/sqla/ajax.py
Original file line number Diff line number Diff line change
Expand Up @@ -64,7 +64,7 @@ def get_query(self):
def get_one(self, pk):
# prevent autoflush from occuring during populate_obj
with self.session.no_autoflush:
return self.get_query().get(pk)
return self.session.get(self.model, pk)

def get_list(self, term, offset=0, limit=DEFAULT_PAGE_SIZE):
query = self.get_query()
Expand Down
1 change: 0 additions & 1 deletion flask_admin/contrib/sqla/filters.py
Original file line number Diff line number Diff line change
Expand Up @@ -207,7 +207,6 @@ def apply(self, query, value, alias=None):
class DateNotBetweenFilter(DateBetweenFilter):
def apply(self, query, value, alias=None):
start, end = value
# ~between() isn't possible until sqlalchemy 1.0.0
return query.filter(not_(self.get_column(alias).between(start, end)))

def operation(self):
Expand Down
14 changes: 5 additions & 9 deletions flask_admin/contrib/sqla/tools.py
Original file line number Diff line number Diff line change
@@ -1,19 +1,15 @@
import types

from sqlalchemy import tuple_, or_, and_, inspect
try:
# Attempt _class_resolver import from SQLALchemy 1.4/2.0 module architecture.
from sqlalchemy.orm.clsregistry import _class_resolver
except ImportError:
# If 1.4/2.0 module import fails, fall back to <1.3.x architecture.
from sqlalchemy.ext.declarative.clsregistry import _class_resolver # type: ignore[no-redef]
from sqlalchemy.orm.clsregistry import _class_resolver
from sqlalchemy.ext.hybrid import hybrid_property
try:
# Attempt ASSOCATION_PROXY import from pre-2.0 release
from sqlalchemy.ext.associationproxy import ASSOCIATION_PROXY
except ImportError:
# SQLAlchemy 2.0
from sqlalchemy.ext.associationproxy import AssociationProxyExtensionType # type: ignore[attr-defined]
ASSOCIATION_PROXY = AssociationProxyExtensionType.ASSOCIATION_PROXY
except ImportError:
from sqlalchemy.ext.associationproxy import ASSOCIATION_PROXY

from sqlalchemy.sql.operators import eq # type: ignore[attr-defined]
from sqlalchemy.exc import DBAPIError
from sqlalchemy.orm.attributes import InstrumentedAttribute
Expand Down
2 changes: 1 addition & 1 deletion flask_admin/tests/sqla/test_inlineform.py
Original file line number Diff line number Diff line change
Expand Up @@ -92,7 +92,7 @@ class UserModelView(ModelView):
rv = client.post('/admin/user/edit/?id=2', data=data)
assert rv.status_code == 302
assert User.query.count() == 2
assert User.query.get(2).name == u'barf'
assert db.session.get(User, 2).name == 'barf'
assert UserInfo.query.count() == 1
assert UserInfo.query.one().key == u'bar'

Expand Down
6 changes: 5 additions & 1 deletion flask_admin/tests/sqla/test_multi_pk.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,11 @@
from .test_basic import CustomModelView

from flask_sqlalchemy.model import Model
from sqlalchemy.ext.declarative import declarative_base
try:
# SQLAlchemy 2.0
from sqlalchemy.orm import declarative_base
except ImportError:
from sqlalchemy.ext.declarative import declarative_base


def test_multiple_pk(app, db, admin):
Expand Down
4 changes: 3 additions & 1 deletion flask_admin/tests/sqla/test_postgres.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
from .test_basic import CustomModelView

from sqlalchemy import text
from sqlalchemy.dialects.postgresql import HSTORE, JSON
from citext import CIText

Expand Down Expand Up @@ -80,7 +81,8 @@ class CITextModel(postgres_db.Model):
id = postgres_db.Column(postgres_db.Integer, primary_key=True, autoincrement=True)
citext_test = postgres_db.Column(CIText)

postgres_db.engine.execute('CREATE EXTENSION IF NOT EXISTS citext')
with postgres_db.engine.begin() as connection:
connection.execute(text('CREATE EXTENSION IF NOT EXISTS citext'))
postgres_db.create_all()

view = CustomModelView(CITextModel, postgres_db.session)
Expand Down
5 changes: 1 addition & 4 deletions pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ dependencies = [
[project.optional-dependencies]
sqlalchemy = [
"flask-sqlalchemy>=3",
"sqlalchemy>=1.4,<2",
"sqlalchemy>=1.4",
]
sqlalchemy-with-utils = [
"Flask-Admin[sqlalchemy]",
Expand Down Expand Up @@ -118,9 +118,6 @@ filterwarnings = [

# `flask.testing` accesses this attribute; remove when they have updated their code.
"default:The '__version__' attribute is deprecated and will be removed in Werkzeug 3\\.1\\.:DeprecationWarning",

# TODO: Remove when we've added SQLAlchemy 2.0 compatibility
"default:Deprecated API features detected!:DeprecationWarning:flask_admin.tests.sqla.test_basic:99",
]

[tool.coverage.run]
Expand Down
5 changes: 4 additions & 1 deletion tox.ini
Original file line number Diff line number Diff line change
@@ -1,8 +1,10 @@
[tox]
envlist =
py3{8,9,10,11,12}
py3{8,12}-sqlalchemy1
py312-noflaskbabel # only tested against latest of all configurations, sans flask-babel
py312-flaskmongoengine
py312-flaskmongoengine-sqlalchemy1

# style
typing
docs
Expand All @@ -24,6 +26,7 @@ deps = -r requirements/tests.in
commands_pre =
noflaskbabel: pip uninstall -y flask-babel
flaskmongoengine: pip install Flask==2.1.3 Werkzeug==2.3.8 flask-sqlalchemy<3
sqlalchemy1: pip install sqlalchemy<2 flask-sqlalchemy<3.1
commands =
flaskmongoengine: pytest -v --tb=short --basetemp={envtmpdir} flask_admin/tests -W 'default::DeprecationWarning' {posargs}
!flaskmongoengine: pytest -v --tb=short --basetemp={envtmpdir} flask_admin/tests --ignore flask_admin/tests/mongoengine {posargs}
Expand Down