fedora-copr/flask-whooshee

Flask-Whooshee overwrites custom query class.

Closed this issue · 1 comments

In FlaskBB we're attempting to implement a soft-delete feature by way of the linked blog post. However, we also index several of these models with Whooshee, which loses the custom query class.

Offending line

Looks like a simple fix could be to check if there is a query class already registered to the model and augment it with the whooshee query class, something like the following might work.

query_class = getattr(model, 'query_class', None)
# check type to ensure stable MRO
if model.query_class is not None and query_class is not BaseQuery:
    query_class_name = model.query_class.__name__
    model.query_class = type('Whooshee{}'.format(query_class_name), (model.query_class, WhoosheeQuery), {})
else:
    model.query_class = WhoosheeQuery

I'm going to test this in FlaskBB and see how it works and issue a PR if there is interest in this.

Fixed by #42, closing.