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

Stop using deprecated BaseQuery #85

Merged
merged 2 commits into from
Feb 13, 2024
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
9 changes: 6 additions & 3 deletions flask_whooshee.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,10 @@
from whoosh.filedb.filestore import RamStorage

from flask import current_app
from flask_sqlalchemy import BaseQuery
try:
from flask_sqlalchemy.query import Query
except ImportError:
from flask_sqlalchemy import BaseQuery as Query
from sqlalchemy import text, event
from sqlalchemy.inspection import inspect
from sqlalchemy.orm.mapper import Mapper
Expand Down Expand Up @@ -48,7 +51,7 @@ def _assure_dirs_exists(path):
if err.errno != errno.EEXIST:
raise

class WhoosheeQuery(BaseQuery):
class WhoosheeQuery(Query):
"""An override for SQLAlchemy query used to do fulltext search."""

def whooshee_search(self, search_string, group=whoosh.qparser.OrGroup, whoosheer=None,
Expand Down Expand Up @@ -293,7 +296,7 @@ def register_whoosheer(self, wh):
pass

# ensure there can be a stable MRO
elif query_class not in (BaseQuery, SQLAQuery, WhoosheeQuery):
elif query_class not in (Query, SQLAQuery, WhoosheeQuery):
query_class_name = query_class.__name__
model.query_class = type(
"Whooshee{}".format(query_class_name), (query_class, self.query), {}
Expand Down
10 changes: 7 additions & 3 deletions test.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,11 @@
import whoosh
from whoosh.filedb.filestore import RamStorage
from flask import Flask
from flask_sqlalchemy import SQLAlchemy, BaseQuery
from flask_sqlalchemy import SQLAlchemy
try:
from flask_sqlalchemy.query import Query
except ImportError:
from flask_sqlalchemy import BaseQuery as Query
from sqlalchemy.orm import Query as SQLAQuery
from flask_whooshee import AbstractWhoosheer, Whooshee, WhoosheeQuery

Expand Down Expand Up @@ -712,14 +716,14 @@ def setUp(self):
self.wh = Whooshee(self.app)

def test_mixes_with_model_query(self):
class CustomQueryClass(BaseQuery):
class CustomQueryClass(Query):
pass

self._make_model_and_whoosheer(CustomQueryClass)
self.assertEqual('WhoosheeCustomQueryClass', self.user_model.query_class.__name__)

def test_doesnt_mix_with_default_query_class(self):
self._make_model_and_whoosheer(BaseQuery)
self._make_model_and_whoosheer(Query)
self.assertIs(self.wh.query, self.user_model.query_class)

def test_doesnt_mix_with_explicit_whooshee_query_class(self):
Expand Down
Loading