Do not check for integrity error the required fields with set method

Closes #13745
(grafted from 55087fb59fc93731a341c3436c5cbc99ea4cf3b1)

--HG--
branch : 7.0
This commit is contained in:
Cédric Krier committed 2024-12-11 11:02:07 +01:00
1 parent 6e030c62ee
commit 761fb07908
4 files changed
+39 -3

No files matched your search

+1 -1
View File
@@ -546,7 +546,7 @@ class ModelSQL(ModelStorage):
field = cls._fields[field_name]
# Check required fields
if (field.required
and field.sql_type()
and not hasattr(field, 'set')
and field_name not in ('create_uid', 'create_date')):
if values.get(field_name) is None:
raise RequiredValidationError(
+17 -1
View File
@@ -1,7 +1,7 @@
# This file is part of Tryton. The COPYRIGHT file at the top level of
# this repository contains the full copyright notices and license terms.
from trytond.model import ModelSQL, fields
from trytond.model import Check, ModelSQL, fields
from trytond.pool import Pool
@@ -27,6 +27,21 @@ class BinaryRequired(ModelSQL):
binary = fields.Binary('Binary Required', required=True)
class BinaryRequiredSQLConstraint(ModelSQL):
"Binary Required SQL Constraint"
__name__ = 'test.binary_required_sql_constraint'
binary = fields.Binary('Binary Required', required=True)
constraint = fields.Boolean("Constraint")
@classmethod
def __setup__(cls):
super().__setup__()
t = cls.__table__()
cls._sql_constraints.append(
('constraint', Check(t, t.constraint),
'tests.msg_binary_required_sql_constraint'))
class BinaryFileStorage(ModelSQL):
"Binary in FileStorage"
__name__ = 'test.binary_filestorage'
@@ -39,5 +54,6 @@ def register(module):
Binary,
BinaryDefault,
BinaryRequired,
BinaryRequiredSQLConstraint,
BinaryFileStorage,
module=module, type_='model')
+3
View File
@@ -21,5 +21,8 @@ this repository contains the full copyright notices and license terms. -->
<record model="ir.message" id="msg_one2one_relation_target_unique">
<field name="text">Target must be unique.</field>
</record>
<record model="ir.message" id="msg_binary_required_sql_constraint">
<field name="text">Constraint must be checked.</field>
</record>
</data>
</tryton>
+18 -1
View File
@@ -8,7 +8,8 @@ from sql import Literal
from trytond.config import config
from trytond.model import fields
from trytond.model.exceptions import RequiredValidationError
from trytond.model.exceptions import (
RequiredValidationError, SQLConstraintError)
from trytond.pool import Pool
from trytond.tests.test_tryton import activate_module, with_transaction
from trytond.transaction import Transaction
@@ -88,6 +89,22 @@ class FieldBinaryTestCase(unittest.TestCase):
'binary': cast(b''),
}])
@with_transaction()
def test_create_required_with_invalid_sql_constraint(self):
"Test create required binary with invalid SQL constraint"
Binary = Pool().get('test.binary_required_sql_constraint')
binary, = Binary.create([{
'binary': cast(b'foo'),
'constraint': True,
}])
with self.assertRaises(SQLConstraintError):
binary, = Binary.create([{
'binary': cast(b'foo'),
'constraint': False,
}])
@with_transaction()
def test_create_filestorage(self):
"Test create binary with filestorage"