From 082405d8ef63d60a1c594a7a640beaf182327569 Mon Sep 17 00:00:00 2001 From: collerek Date: Tue, 9 Mar 2021 20:41:17 +0100 Subject: [PATCH] use TEXT for all backends --- ormar/fields/base.py | 2 -- ormar/fields/foreign_key.py | 2 -- ormar/fields/many_to_many.py | 2 -- ormar/fields/sqlalchemy_encrypted.py | 8 ++------ tests/test_encrypted_columns.py | 2 -- 5 files changed, 2 insertions(+), 14 deletions(-) diff --git a/ormar/fields/base.py b/ormar/fields/base.py index 041d934..c58348c 100644 --- a/ormar/fields/base.py +++ b/ormar/fields/base.py @@ -58,7 +58,6 @@ class BaseField(FieldInfo): encrypt_secret: str encrypt_backend: EncryptBackends = EncryptBackends.NONE encrypt_custom_backend: Optional[Type[EncryptBackend]] = None - encrypt_max_length: int = 5000 default: Any server_default: Any @@ -304,7 +303,6 @@ class BaseField(FieldInfo): encrypt_secret=cls.encrypt_secret, encrypt_backend=cls.encrypt_backend, encrypt_custom_backend=cls.encrypt_custom_backend, - encrypt_max_length=cls.encrypt_max_length, ), nullable=cls.nullable, index=cls.index, diff --git a/ormar/fields/foreign_key.py b/ormar/fields/foreign_key.py index 0aafd5e..a0122d4 100644 --- a/ormar/fields/foreign_key.py +++ b/ormar/fields/foreign_key.py @@ -189,14 +189,12 @@ def ForeignKey( # noqa CFQ002 encrypt_secret = kwargs.pop("encrypt_secret", None) encrypt_backend = kwargs.pop("encrypt_backend", None) encrypt_custom_backend = kwargs.pop("encrypt_custom_backend", None) - encrypt_max_length = kwargs.pop("encrypt_max_length", None) not_supported = [ default, encrypt_secret, encrypt_backend, encrypt_custom_backend, - encrypt_max_length, ] if any(x is not None for x in not_supported): raise ModelDefinitionError( diff --git a/ormar/fields/many_to_many.py b/ormar/fields/many_to_many.py index ca26364..2382fa5 100644 --- a/ormar/fields/many_to_many.py +++ b/ormar/fields/many_to_many.py @@ -100,14 +100,12 @@ def ManyToMany( encrypt_secret = kwargs.pop("encrypt_secret", None) encrypt_backend = kwargs.pop("encrypt_backend", None) encrypt_custom_backend = kwargs.pop("encrypt_custom_backend", None) - encrypt_max_length = kwargs.pop("encrypt_max_length", None) not_supported = [ default, encrypt_secret, encrypt_backend, encrypt_custom_backend, - encrypt_max_length, ] if any(x is not None for x in not_supported): raise ModelDefinitionError( diff --git a/ormar/fields/sqlalchemy_encrypted.py b/ormar/fields/sqlalchemy_encrypted.py index f08c43c..a198bd6 100644 --- a/ormar/fields/sqlalchemy_encrypted.py +++ b/ormar/fields/sqlalchemy_encrypted.py @@ -124,7 +124,6 @@ class EncryptedString(types.TypeDecorator): **kwargs: Any, ) -> None: _field_type = kwargs.pop("_field_type") - encrypt_max_length = kwargs.pop("encrypt_max_length", 5000) super().__init__() if not cryptography: # pragma: nocover raise ModelDefinitionError( @@ -138,7 +137,6 @@ class EncryptedString(types.TypeDecorator): self._field_type: Type["BaseField"] = _field_type self._underlying_type: Any = _field_type.column_type self._key: Union[str, Callable] = encrypt_secret - self.max_length: int = encrypt_max_length type_ = self._field_type.__type__ if type_ is None: # pragma: nocover raise ModelDefinitionError( @@ -147,12 +145,10 @@ class EncryptedString(types.TypeDecorator): self.type_: Any = type_ def __repr__(self) -> str: # pragma: nocover - return f"VARCHAR({self.max_length})" + return f"TEXT()" def load_dialect_impl(self, dialect: DefaultDialect) -> Any: - if dialect.name == 'mysql': # pragma: nocover - return dialect.type_descriptor(types.TEXT()) - return dialect.type_descriptor(types.VARCHAR(self.max_length)) + return dialect.type_descriptor(types.TEXT()) def _refresh(self) -> None: key = self._key() if callable(self._key) else self._key diff --git a/tests/test_encrypted_columns.py b/tests/test_encrypted_columns.py index 5eff02f..323563f 100644 --- a/tests/test_encrypted_columns.py +++ b/tests/test_encrypted_columns.py @@ -54,7 +54,6 @@ class Author(ormar.Model): birth_year: int = ormar.Integer( nullable=True, encrypt_secret="secure89key%^&psdijfipew", - encrypt_max_length=200, encrypt_backend=ormar.EncryptBackends.FERNET, ) test_text: str = ormar.Text(default="", **default_fernet) @@ -146,7 +145,6 @@ def test_wrong_backend(): def test_db_structure(): assert Author.Meta.table.c.get("name").type.__class__ == EncryptedString - assert Author.Meta.table.c.get("birth_year").type.max_length == 200 @pytest.mark.asyncio