From 32d5cdcb30bfde99b9acaff42002c02f50f7676b Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Sebasti=C3=A1n=20Ram=C3=ADrez?= Date: Mon, 7 Jan 2019 17:59:25 +0400 Subject: [PATCH] Fix BaseConfig max_anystr_length default to fixed number to None (#350) * Fix BaseConfig max_anystr_length default to fixed number to None * Update History --- HISTORY.rst | 2 ++ pydantic/main.py | 4 ++-- tests/test_construction.py | 12 ++++++++++++ 3 files changed, 16 insertions(+), 2 deletions(-) diff --git a/HISTORY.rst b/HISTORY.rst index 76e7a38..9ba3b5d 100644 --- a/HISTORY.rst +++ b/HISTORY.rst @@ -10,6 +10,8 @@ v0.18.0 (unreleased) ``whole`` validators being called for sub-fields, fix #132 by @samuelcolvin * improve documentation for settings priority and allow it to be easily changed, #343 by @samuelcolvin * fix ``ignore_extra=False`` and ``allow_population_by_alias=True``, fix #257 by @samuelcolvin +* **breaking change**: Set ``BaseConfig`` attributes ``min_anystr_length`` and ``max_anystr_length`` to + ``None`` by default, fix #349 in #350, by @tiangolo v0.17.0 (2018-12-27) .................... diff --git a/pydantic/main.py b/pydantic/main.py index 3c89d04..aa781c3 100644 --- a/pydantic/main.py +++ b/pydantic/main.py @@ -22,8 +22,8 @@ from .validators import dict_validator class BaseConfig: title = None anystr_strip_whitespace = False - min_anystr_length = 0 - max_anystr_length = 2 ** 16 + min_anystr_length = None + max_anystr_length = None validate_all = False ignore_extra = True allow_extra = False diff --git a/tests/test_construction.py b/tests/test_construction.py index 339d838..0d7b214 100644 --- a/tests/test_construction.py +++ b/tests/test_construction.py @@ -25,6 +25,18 @@ def test_construct_missing(): assert "'Model' object has no attribute 'b'" in str(exc_info) +def test_large_any_str(): + class Model(BaseModel): + a: bytes + b: str + + content_bytes = b"x" * (2 ** 16 + 1) + content_str = "x" * (2 ** 16 + 1) + m = Model(a=content_bytes, b=content_str) + assert m.a == content_bytes + assert m.b == content_str + + def test_simple_copy(): m = Model(a=24) m2 = m.copy()