art1415926535 / graphene-sqlalchemy-filter

Filters for Graphene SQLAlchemy integration
https://pypi.org/project/graphene-sqlalchemy-filter/
MIT License
118 stars 34 forks source link

cls.aliased returns None periodically #37

Open hddn opened 3 years ago

hddn commented 3 years ago

Hi! I'm using this library with Fast API and experiencing an issue with filters with joins. Sometimes this piece of code returns None:

    @classmethod
    def _aliases_from_query(cls, query: Query) -> 'Dict[str, _MapperEntity]':
        """
        Get aliases from SQLAlchemy query.

        Args:
            query: SQLAlchemy query.

        Returns:
            Dictionary of model aliases.

        """
        aliases = {
            (mapper._target, mapper.name): mapper.entity
            for mapper in query._join_entities
        }

        return aliases

mapper.entity is None from time to time. This is because it uses weakref and entity object gets garbage collected or something like that I didn't dig that much. When I try to join the table once more sqlalchemy complains that it's already joined. Maybe you @art1415926535 could give some advice on how to fix that? Thanks

art1415926535 commented 3 years ago

Haven't seen any cases where mapper.entity returns None. It would be great to have a test or example.