diff --git a/CHANGELOG b/CHANGELOG index 698c98b578..abe080adbc 100644 --- a/CHANGELOG +++ b/CHANGELOG @@ -1,3 +1,4 @@ +* Allow PYSON size of fields to be None * Add command line completion with argcomplete * Include record name and value in validation error message * Add header parameter on export data diff --git a/trytond/model/fields/field.py b/trytond/model/fields/field.py index 3ce4cbbdbf..47f2aac974 100644 --- a/trytond/model/fields/field.py +++ b/trytond/model/fields/field.py @@ -74,7 +74,7 @@ def size_validate(value): if value is not None: assert isinstance(value, (int, PYSON)), 'size must be PYSON' if hasattr(value, 'types'): - assert value.types() == {int}, \ + assert value.types() <= {int, type(None)}, \ 'size must return integer' diff --git a/trytond/model/modelstorage.py b/trytond/model/modelstorage.py index 974d03ac2a..ef966c5319 100644 --- a/trytond/model/modelstorage.py +++ b/trytond/model/modelstorage.py @@ -1395,7 +1395,7 @@ class ModelStorage(Model): else: field_size = field.size size = len(getattr(record, field_name) or '') - if (size > field_size >= 0): + if field_size is not None and (size > field_size >= 0): error_args = cls.__names__(field_name, record) error_args['size'] = size error_args['max_size'] = field_size diff --git a/trytond/tests/test_field_char.py b/trytond/tests/test_field_char.py index 7eec01d2d6..eed0032fb2 100644 --- a/trytond/tests/test_field_char.py +++ b/trytond/tests/test_field_char.py @@ -444,6 +444,17 @@ class FieldCharTestCase(unittest.TestCase, CommonTestCaseMixin): 'size': 5, }]) + @with_transaction() + def test_create_size_pyson_none(self): + "Test create char with PYSON size as None" + pool = Pool() + Char = pool.get('test.char_size_pyson') + + char, = Char.create([{ + 'char': "foo", + 'size': None, + }]) + @with_transaction() def test_create_invalid_char(self): "Test create char with invalid char" diff --git a/trytond/tests/test_field_one2many.py b/trytond/tests/test_field_one2many.py index a6d62a89bf..922288b55f 100644 --- a/trytond/tests/test_field_one2many.py +++ b/trytond/tests/test_field_one2many.py @@ -521,6 +521,19 @@ class FieldOne2ManyTestCase(unittest.TestCase, CommonTestCaseMixin): ], }]) + @with_transaction() + def test_create_size_pyson_none(self): + "Test create one2many with PYSON size as None" + pool = Pool() + One2Many = pool.get('test.one2many_size_pyson') + + one2many, = One2Many.create([{ + 'limit': None, + 'targets': [ + ('create', [{}]), + ], + }]) + @with_transaction() def test_create_filter(self): "Test create one2many with filter"