changeset 6ef3220ac4e0 in trytond:default
details: https://hg.tryton.org/trytond?cmd=changeset&node=6ef3220ac4e0
description:
        Allow PYSON size of fields to be None

        issue11643
        review411571003
diffstat:

 CHANGELOG                            |   1 +
 trytond/model/fields/field.py        |   2 +-
 trytond/model/modelstorage.py        |   2 +-
 trytond/tests/test_field_char.py     |  11 +++++++++++
 trytond/tests/test_field_one2many.py |  13 +++++++++++++
 5 files changed, 27 insertions(+), 2 deletions(-)

diffs (76 lines):

diff -r 43d123a4877d -r 6ef3220ac4e0 CHANGELOG
--- a/CHANGELOG Thu Sep 08 13:10:15 2022 +0200
+++ b/CHANGELOG Thu Sep 08 13:15:54 2022 +0200
@@ -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 -r 43d123a4877d -r 6ef3220ac4e0 trytond/model/fields/field.py
--- a/trytond/model/fields/field.py     Thu Sep 08 13:10:15 2022 +0200
+++ b/trytond/model/fields/field.py     Thu Sep 08 13:15:54 2022 +0200
@@ -74,7 +74,7 @@
     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 -r 43d123a4877d -r 6ef3220ac4e0 trytond/model/modelstorage.py
--- a/trytond/model/modelstorage.py     Thu Sep 08 13:10:15 2022 +0200
+++ b/trytond/model/modelstorage.py     Thu Sep 08 13:15:54 2022 +0200
@@ -1395,7 +1395,7 @@
                         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 -r 43d123a4877d -r 6ef3220ac4e0 trytond/tests/test_field_char.py
--- a/trytond/tests/test_field_char.py  Thu Sep 08 13:10:15 2022 +0200
+++ b/trytond/tests/test_field_char.py  Thu Sep 08 13:15:54 2022 +0200
@@ -445,6 +445,17 @@
                         }])
 
     @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"
         Char = Pool().get('test.char')
diff -r 43d123a4877d -r 6ef3220ac4e0 trytond/tests/test_field_one2many.py
--- a/trytond/tests/test_field_one2many.py      Thu Sep 08 13:10:15 2022 +0200
+++ b/trytond/tests/test_field_one2many.py      Thu Sep 08 13:15:54 2022 +0200
@@ -522,6 +522,19 @@
                         }])
 
     @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"
         One2Many = Pool().get('test.one2many_filter')

Reply via email to