You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
When we want to use a filter on a column of type PhonenumberType with a like statement, the default behavior produce an SQL
query with a phonenumber constructed with default US region:
SQL produced (sqlalchemy engine echo on): SELECT phone_number.phone_number FROM phone_number WHERE phone_number.phone_number LIKE %s
Bound values produced (incorrect): ('+1456')
Bound values expected (correct): ('%456%')
Possible workaround: make the type coercion return a string for the like (and notlike) statements. We have subclassed PhonenumberType to bypass this limitation (inspired by the original function from SQLAlchemy):
class PhoneNumberType(sqlalchemy_utils.types.phone_number.PhoneNumberType):
def coerce_compared_value(self, op, value):
if op in (like_op, notlike_op):
return String()
else:
return self
Is it possible to add this behavior to the library, or have we missed something ?
When we want to use a filter on a column of type PhonenumberType with a like statement, the default behavior produce an SQL
query with a phonenumber constructed with default US region:
SQL produced (sqlalchemy engine echo on):
SELECT phone_number.phone_number FROM phone_number WHERE phone_number.phone_number LIKE %s
Bound values produced (incorrect):
('+1456')
Bound values expected (correct):
('%456%')
Possible workaround: make the type coercion return a string for the like (and notlike) statements. We have subclassed PhonenumberType to bypass this limitation (inspired by the original function from SQLAlchemy):
Is it possible to add this behavior to the library, or have we missed something ?
OS: Debian 11 bullseye
Python: 3.9.2
SQLAlchemy_utils: 0.37.9
Regards
The text was updated successfully, but these errors were encountered: