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

WhoosheeQuery object has no attribute '_join_entities' #60

Closed
thebenisson opened this issue Apr 26, 2021 · 3 comments · Fixed by #62
Closed

WhoosheeQuery object has no attribute '_join_entities' #60

thebenisson opened this issue Apr 26, 2021 · 3 comments · Fixed by #62

Comments

@thebenisson
Copy link

thebenisson commented Apr 26, 2021

This is my model class

class Blog(db.Model):
     id = db.Column(db.Integer, primary_key=True)
    splash = db.Column(db.String(128))
    author = db.Column(db.String(20), nullable=False, index=True)
    title = db.Column(db.String(28), nullable=False, index=True)
    message = db.Column(db.Text, nullable=False, index=True)
    isPublished = db.Column(db.Boolean, default=False)
    datePosted = db.Column(db.DateTime)
    modified_at = db.Column(db.DateTime)
    created_at = db.Column(db.DateTime, default=datetime.utcnow())
    categories = db.relationship(
        'Category',
        secondary=blogcategories,
        backref=db.backref('blogs', lazy='dynamic'),
        lazy='dynamic'
    )

I get the error: Flask-Whooshee a error 'WhoosheeQuery' object has no attribute '_join_entities' when I do

 Blog.query.whooshee_search('<some-string>', order_by_relevance=5).all()

Since I only needed the full-text feature on one table, I commented out the joined entities part in flask_whooshee.py as shown

if not whoosheer:
            ### inspiration taken from flask-WhooshAlchemy
            # find out all entities in join
            entities = set()
            # directly queried entities
            for cd in self.column_descriptions:
                entities.add(cd['type'])
            # joined entities
            # if self._join_entities and isinstance(self._join_entities[0], Mapper):
            #     # SQLAlchemy >= 0.8.0
            #     entities.update(set([x.entity for x in self._join_entities]))
            # else:
            #     # SQLAlchemy < 0.8.0
            #     entities.update(set(self._join_entities))
            # make sure we can work with aliased entities
            unaliased = set()
            for entity in entities:
                if isinstance(entity, (AliasedClass, AliasedInsp)):
                    unaliased.add(inspect(entity).mapper.class_)
                else:
                    unaliased.add(entity)

            whoosheer = next(w for w in _get_config(self)['whoosheers']
                             if set(w.models) == unaliased)

Has anyone got a better fix?

@HOODY95
Copy link

HOODY95 commented Apr 27, 2021

I have the same issue, I was looking around for a solution but it seems that _join_entities does not exist in SqlAlchemy version > 1.4 it is only available from version 1.3 and below

As you can see in the code above it says # SQLAlchemy < 0.8.0

So you have to check which version of SqlAlchemy you are using

But I also hope it gets updated to support the latest version of SqlAlchemy

@frenzymadness
Copy link
Contributor

Also, almost all the tests are failing because of this issue.

@sh4nks
Copy link
Contributor

sh4nks commented Jul 13, 2021

@Sneaky-Bit @frenzymadness @thebenisson
See #61 for a potential fix

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging a pull request may close this issue.

4 participants