Skip to content

Commit

Permalink
fix mssql
Browse files Browse the repository at this point in the history
  • Loading branch information
dpgaspar committed Apr 20, 2023
1 parent 74bba8d commit d5eebe8
Show file tree
Hide file tree
Showing 2 changed files with 25 additions and 14 deletions.
34 changes: 23 additions & 11 deletions flask_appbuilder/models/sqla/filters.py
Original file line number Diff line number Diff line change
Expand Up @@ -34,13 +34,13 @@

def get_field_setup_query(query, model, column_name):
"""
Help function for SQLA filters, checks for dot notation on column names.
If it exists, will join the query with the model
from the first part of the field name.
Help function for SQLA filters, checks for dot notation on column names.
If it exists, will join the query with the model
from the first part of the field name.
example:
Contact.created_by: if created_by is a User model,
it will be joined to the query.
example:
Contact.created_by: if created_by is a User model,
it will be joined to the query.
"""
if not hasattr(model, column_name):
# it's an inner obj attr
Expand Down Expand Up @@ -195,7 +195,11 @@ def apply(self, query, value):
logging.warning(
"Filter exception for %s with value %s, will not apply", field, value
)
self.datamodel.session.rollback()
try:
self.datamodel.session.rollback()
except SQLAlchemyError:
# on MSSQL a rollback would fail here
pass
raise ApplyFilterException(exception=exc)
return query.filter(field == rel_obj)

Expand All @@ -212,7 +216,11 @@ def apply(self, query, value):
logging.warning(
"Filter exception for %s with value %s, will not apply", field, value
)
self.datamodel.session.rollback()
try:
self.datamodel.session.rollback()
except SQLAlchemyError:
# on MSSQL a rollback would fail here
pass
raise ApplyFilterException(exception=exc)
return query.filter(field != rel_obj)

Expand All @@ -234,7 +242,11 @@ def apply_item(self, query, field, value_item):
field,
value_item,
)
self.datamodel.session.rollback()
try:
self.datamodel.session.rollback()
except SQLAlchemyError:
# on MSSQL a rollback would fail here
pass
raise ApplyFilterException(exception=exc)

if rel_obj:
Expand Down Expand Up @@ -279,8 +291,8 @@ def apply(self, query, func):

class SQLAFilterConverter(BaseFilterConverter):
"""
Class for converting columns into a supported list of filters
specific for SQLAlchemy.
Class for converting columns into a supported list of filters
specific for SQLAlchemy.
"""

Expand Down
5 changes: 2 additions & 3 deletions flask_appbuilder/tests/security/test_auth_ldap.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,14 +5,13 @@
from unittest.mock import Mock

from flask import Flask

from flask_appbuilder import AppBuilder, SQLA
from flask_appbuilder.security.manager import AUTH_LDAP
from flask_appbuilder.security.sqla.models import Role, User
from flask_appbuilder.security.sqla.models import User
from flask_appbuilder.tests.const import USERNAME_ADMIN, USERNAME_READONLY
import jinja2
import ldap

from flask_appbuilder.tests.const import USERNAME_ADMIN, USERNAME_READONLY

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

0 comments on commit d5eebe8

Please sign in to comment.