Skip to content

Commit

Permalink
SQLAlchemy 2 compatibility for hybrid properties and methods
Browse files Browse the repository at this point in the history
  • Loading branch information
phillipuniverse committed Jan 21, 2024
1 parent d8be639 commit 8328dd8
Showing 1 changed file with 5 additions and 3 deletions.
8 changes: 5 additions & 3 deletions sqlalchemy_filters/models.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@
from sqlalchemy.exc import InvalidRequestError
from sqlalchemy.orm import mapperlib
from sqlalchemy.inspection import inspect
from sqlalchemy.util import symbol
import types

from .exceptions import BadQuery, FieldNotFound, BadSpec
Expand Down Expand Up @@ -57,12 +56,15 @@ def _get_valid_field_names(self):


def _is_hybrid_property(orm_descriptor):
return orm_descriptor.extension_type == symbol('HYBRID_PROPERTY')
# SQLAlchemy 2 treats extension_type as an enum, not a symbol(). Enum is at sqlalchemy.ext.hybrid.HybridExtensionType

return str(orm_descriptor.extension_type) in ("symbol('HYBRID_PROPERTY')", 'HybridExtensionType.HYBRID_PROPERTY')


def _is_hybrid_method(orm_descriptor):
return orm_descriptor.extension_type == symbol('HYBRID_METHOD')
# SQLAlchemy 2 treats extension_type as an enum, not a symbol(). Enum is at sqlalchemy.ext.hybrid.HybridExtensionType

return str(orm_descriptor.extension_type) in ("symbol('HYBRID_METHOD')", 'HybridExtensionType.HYBRID_METHOD')

def get_model_from_table(table): # pragma: no_cover_sqlalchemy_lt_1_4
"""Resolve model class from table object"""
Expand Down

0 comments on commit 8328dd8

Please sign in to comment.