changeset 9068f5a91043 in trytond:default
details: https://hg.tryton.org/trytond?cmd=changeset;node=9068f5a91043
description:
Prevent assign unknown attributes on Model
by adding __slots__ on PoolMeta
issue8567
review254091002
diffstat:
CHANGELOG | 1 +
trytond/model/active.py | 1 +
trytond/model/dictschema.py | 1 +
trytond/model/match.py | 1 +
trytond/model/model.py | 1 +
trytond/model/modelsql.py | 1 +
trytond/model/modelstorage.py | 3 +++
trytond/model/modelview.py | 1 +
trytond/model/multivalue.py | 1 +
trytond/model/order.py | 1 +
trytond/model/tree.py | 1 +
trytond/model/union.py | 1 +
trytond/model/workflow.py | 1 +
trytond/pool.py | 5 ++++-
trytond/tests/test_modelsql.py | 2 +-
trytond/url.py | 5 +++--
trytond/wizard/wizard.py | 1 +
17 files changed, 24 insertions(+), 4 deletions(-)
diffs (213 lines):
diff -r 072934afc39c -r 9068f5a91043 CHANGELOG
--- a/CHANGELOG Sat Sep 07 23:34:55 2019 +0200
+++ b/CHANGELOG Sat Sep 07 23:45:08 2019 +0200
@@ -1,3 +1,4 @@
+* Add __slots__
* Pass app and request to wsgi error handlers
* Add lazy_gettext
* Add format_timedelta to Report
diff -r 072934afc39c -r 9068f5a91043 trytond/model/active.py
--- a/trytond/model/active.py Sat Sep 07 23:34:55 2019 +0200
+++ b/trytond/model/active.py Sat Sep 07 23:45:08 2019 +0200
@@ -6,6 +6,7 @@
class DeactivableMixin(object):
"Mixin to allow to soft deletion of records"
+ __slots__ = ()
active = fields.Boolean(
lazy_gettext('ir.msg_active'),
diff -r 072934afc39c -r 9068f5a91043 trytond/model/dictschema.py
--- a/trytond/model/dictschema.py Sat Sep 07 23:34:55 2019 +0200
+++ b/trytond/model/dictschema.py Sat Sep 07 23:45:08 2019 +0200
@@ -23,6 +23,7 @@
class DictSchemaMixin(object):
+ __slots__ = ()
_rec_name = 'string'
name = fields.Char(lazy_gettext('ir.msg_dict_schema_name'), required=True)
string = fields.Char(
diff -r 072934afc39c -r 9068f5a91043 trytond/model/match.py
--- a/trytond/model/match.py Sat Sep 07 23:34:55 2019 +0200
+++ b/trytond/model/match.py Sat Sep 07 23:45:08 2019 +0200
@@ -3,6 +3,7 @@
class MatchMixin(object):
+ __slots__ = ()
def match(self, pattern, match_none=False):
'''Match on pattern
diff -r 072934afc39c -r 9068f5a91043 trytond/model/model.py
--- a/trytond/model/model.py Sat Sep 07 23:34:55 2019 +0200
+++ b/trytond/model/model.py Sat Sep 07 23:45:08 2019 +0200
@@ -28,6 +28,7 @@
"""
Define a model in Tryton.
"""
+ __slots__ = ('_id', '_values', '_init_values')
_rec_name = 'name'
id = fields.Integer(lazy_gettext('ir.msg_ID'), readonly=True)
diff -r 072934afc39c -r 9068f5a91043 trytond/model/modelsql.py
--- a/trytond/model/modelsql.py Sat Sep 07 23:34:55 2019 +0200
+++ b/trytond/model/modelsql.py Sat Sep 07 23:45:08 2019 +0200
@@ -164,6 +164,7 @@
"""
Define a model with storage in database.
"""
+ __slots__ = ()
_table = None # The name of the table in database
_order = None
_order_name = None # Use to force order field when sorting on Many2One
diff -r 072934afc39c -r 9068f5a91043 trytond/model/modelstorage.py
--- a/trytond/model/modelstorage.py Sat Sep 07 23:34:55 2019 +0200
+++ b/trytond/model/modelstorage.py Sat Sep 07 23:45:08 2019 +0200
@@ -92,6 +92,8 @@
"""
Define a model with storage capability in Tryton.
"""
+ __slots__ = ('_transaction', '_user', '_context', '_ids',
+ '_transaction_cache', '_local_cache')
create_uid = fields.Many2One(
'res.user', lazy_gettext('ir.msg_created_by'), readonly=True)
@@ -1667,6 +1669,7 @@
class EvalEnvironment(dict):
+ __slots__ = ('_record', '_model')
def __init__(self, record, Model):
super(EvalEnvironment, self).__init__()
diff -r 072934afc39c -r 9068f5a91043 trytond/model/modelview.py
--- a/trytond/model/modelview.py Sat Sep 07 23:34:55 2019 +0200
+++ b/trytond/model/modelview.py Sat Sep 07 23:45:08 2019 +0200
@@ -97,6 +97,7 @@
"""
Define a model with views in Tryton.
"""
+ __slots__ = ()
__modules_list = None # Cache for the modules list sorted by dependency
_fields_view_get_cache = Cache('modelview.fields_view_get')
_view_toolbar_get_cache = Cache('modelview.view_toolbar_get')
diff -r 072934afc39c -r 9068f5a91043 trytond/model/multivalue.py
--- a/trytond/model/multivalue.py Sat Sep 07 23:34:55 2019 +0200
+++ b/trytond/model/multivalue.py Sat Sep 07 23:45:08 2019 +0200
@@ -6,6 +6,7 @@
class MultiValueMixin(object):
+ __slots__ = ()
@classmethod
def multivalue_model(cls, field):
diff -r 072934afc39c -r 9068f5a91043 trytond/model/order.py
--- a/trytond/model/order.py Sat Sep 07 23:34:55 2019 +0200
+++ b/trytond/model/order.py Sat Sep 07 23:45:08 2019 +0200
@@ -12,6 +12,7 @@
class SequenceOrderedMixin(object):
"Mixin to order model by a sequence field"
+ __slots__ = ()
@classmethod
def __setup__(cls):
diff -r 072934afc39c -r 9068f5a91043 trytond/model/tree.py
--- a/trytond/model/tree.py Sat Sep 07 23:34:55 2019 +0200
+++ b/trytond/model/tree.py Sat Sep 07 23:45:08 2019 +0200
@@ -12,6 +12,7 @@
def tree(parent='parent', name='name', separator=None):
class TreeMixin(object):
+ __slots__ = ()
if separator:
@classmethod
diff -r 072934afc39c -r 9068f5a91043 trytond/model/union.py
--- a/trytond/model/union.py Sat Sep 07 23:34:55 2019 +0200
+++ b/trytond/model/union.py Sat Sep 07 23:45:08 2019 +0200
@@ -8,6 +8,7 @@
class UnionMixin:
'Mixin to combine models'
+ __slots__ = ()
@staticmethod
def union_models():
diff -r 072934afc39c -r 9068f5a91043 trytond/model/workflow.py
--- a/trytond/model/workflow.py Sat Sep 07 23:34:55 2019 +0200
+++ b/trytond/model/workflow.py Sat Sep 07 23:45:08 2019 +0200
@@ -8,6 +8,7 @@
"""
Mix-in class to handle transition check.
"""
+ __slots__ = ()
_transition_state = 'state'
@classmethod
diff -r 072934afc39c -r 9068f5a91043 trytond/pool.py
--- a/trytond/pool.py Sat Sep 07 23:34:55 2019 +0200
+++ b/trytond/pool.py Sat Sep 07 23:45:08 2019 +0200
@@ -15,6 +15,8 @@
class PoolMeta(type):
def __new__(cls, name, bases, dct):
+ if '__slots__' not in dct and not dct.get('__no_slots__'):
+ dct['__slots__'] = ()
new = type.__new__(cls, name, bases, dct)
if '__name__' in dct:
try:
@@ -215,7 +217,8 @@
continue
try:
previous_cls = self.get(cls.__name__, type=type_)
- cls = type(cls.__name__, (cls, previous_cls), {})
+ cls = type(
+ cls.__name__, (cls, previous_cls), {'__slots__': ()})
except KeyError:
pass
assert issubclass(cls, PoolBase), cls
diff -r 072934afc39c -r 9068f5a91043 trytond/tests/test_modelsql.py
--- a/trytond/tests/test_modelsql.py Sat Sep 07 23:34:55 2019 +0200
+++ b/trytond/tests/test_modelsql.py Sat Sep 07 23:45:08 2019 +0200
@@ -351,7 +351,7 @@
# Create target record without required name
# to ensure create_records is filled to prevent raising
# foreign_model_missing
- record = ParentModel(name="test")
+ record = ParentModel()
record.targets = [TargetModel()]
with self.assertRaises(RequiredValidationError) as cm:
record.save()
diff -r 072934afc39c -r 9068f5a91043 trytond/url.py
--- a/trytond/url.py Sat Sep 07 23:34:55 2019 +0200
+++ b/trytond/url.py Sat Sep 07 23:45:08 2019 +0200
@@ -17,6 +17,7 @@
class URLAccessor(object):
+ __slots__ = ()
def __get__(self, inst, cls):
from trytond.model import Model
@@ -43,5 +44,5 @@
class URLMixin(object):
-
- __url__ = URLAccessor()
+ __slots__ = ()
+ __url__ = URLAccessor()
diff -r 072934afc39c -r 9068f5a91043 trytond/wizard/wizard.py
--- a/trytond/wizard/wizard.py Sat Sep 07 23:34:55 2019 +0200
+++ b/trytond/wizard/wizard.py Sat Sep 07 23:45:08 2019 +0200
@@ -178,6 +178,7 @@
class Wizard(URLMixin, PoolBase):
+ __no_slots__ = True # To allow setting State
start_state = 'start'
end_state = 'end'