Allow PYSON size of fields to be None

issue11643
review411571003
This commit is contained in:
Cédric Krier
2022-09-08 13:15:54 +02:00
parent d1ea8ba864
commit 7dd4445f56
5 changed files with 27 additions and 2 deletions
+1
View File
@@ -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
+1 -1
View File
@@ -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'
+1 -1
View File
@@ -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
+11
View File
@@ -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"
+13
View File
@@ -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"