From 94db2542aec8e380f5bfe604c97ce091cbf650d5 Mon Sep 17 00:00:00 2001 From: Ryan Leckey Date: Mon, 19 Aug 2013 10:12:14 -0700 Subject: [PATCH] Add dialect fork of the impl of PasswordType for postgresql. --- sqlalchemy_utils/types/password.py | 15 +++++++++++++-- 1 file changed, 13 insertions(+), 2 deletions(-) diff --git a/sqlalchemy_utils/types/password.py b/sqlalchemy_utils/types/password.py index ec6d1c6..7e52d87 100644 --- a/sqlalchemy_utils/types/password.py +++ b/sqlalchemy_utils/types/password.py @@ -2,6 +2,7 @@ import six import weakref from sqlalchemy_utils import ImproperlyConfigured from sqlalchemy import types +from sqlalchemy.dialects import postgresql from .scalar_coercible import ScalarCoercible try: @@ -101,8 +102,18 @@ class PasswordType(types.TypeDecorator, ScalarCoercible): # Set the max_length to the maximum calculated max length. max_length = max(max_lengths) - # Set the impl to the now-calculated max length. - self.impl = types.VARBINARY(max_length) + # Set the length to the now-calculated max length. + self.length = max_length + + def load_dialect_impl(self, dialect): + if dialect.name == 'postgresql': + # Use a BYTEA type for postgresql. + impl = postgresql.BYTEA(self.length) + return dialect.type_descriptor(impl) + + # Use a VARBINARY for all other dialects. + impl = types.VARBINARY(self.length) + return dialect.type_descriptor(impl) def process_bind_param(self, value, dialect): if isinstance(value, Password):