[FIX] core: do not register classes when _module is falsy

The goal is to avoid a class from being added in the dictionary
`MetaModel.module_to_models`.

We use this feature in tests to prevent classes extending models from
triggering bugs when reloading the registry (for whatever reason).

X-original-commit: 12db61b787b2035bf0c1f2a68a24449d484744c8
This commit is contained in:
Raphael Collet
2020-04-02 23:54:32 +00:00
parent 0f7d670434
commit 46b7fb5984
2 changed files with 5 additions and 1 deletions
@@ -2615,6 +2615,7 @@ class TestSelectionOndeleteAdvanced(common.TransactionCase):
def test_ondelete_unexisting_policy(self):
class Foo(models.Model):
_module = None
_inherit = self.MODEL_REQUIRED
my_selection = fields.Selection(selection_add=[
@@ -2628,6 +2629,7 @@ class TestSelectionOndeleteAdvanced(common.TransactionCase):
def test_ondelete_default_no_default(self):
class Foo(models.Model):
_module = None
_inherit = self.MODEL_BASE
my_selection = fields.Selection(selection_add=[
@@ -2641,6 +2643,7 @@ class TestSelectionOndeleteAdvanced(common.TransactionCase):
def test_ondelete_required_null_explicit(self):
class Foo(models.Model):
_module = None
_inherit = self.MODEL_REQUIRED
my_selection = fields.Selection(selection_add=[
@@ -2654,6 +2657,7 @@ class TestSelectionOndeleteAdvanced(common.TransactionCase):
def test_ondelete_required_null_implicit(self):
class Foo(models.Model):
_module = None
_inherit = self.MODEL_REQUIRED
my_selection = fields.Selection(selection_add=[
+1 -1
View File
@@ -161,7 +161,7 @@ class MetaModel(api.Meta):
self._module = self._get_addon_name(self.__module__)
# Remember which models to instanciate for this module.
if not self._custom:
if self._module:
self.module_to_models[self._module].append(self)
# check for new-api conversion error: leave comma after field definition