-
-
Notifications
You must be signed in to change notification settings - Fork 1.5k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
[FIX] database_cleanup: Fix test #612
Conversation
- Follow recommendation from odoo/odoo#13458 (comment) - Fix blocking tables issues - Delete trash information
# Release the delete of ir_module_module pending | ||
self.env.cr.rollback() | ||
cr2.execute( | ||
"DELETE FROM ir_module_module WHERE id=%s", (module.id,)) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
if this is necessary, the test has failed. Or better: Then we have the problem that the commits the module needs to do shouldn't be committed. Maybe it's better to defuse cr.commit
at the beginning of the test and reinstate it here?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
If you run 2 times this test, you will a contraint error of ir_module_module name unique.
It's because the process: self.env['ir.module.module'].create(...)
and RegistryManager.registries[self.env.cr.dbname] = original_registry
have a custom cursor with commit (different to current self.env.cr
)
Then the test purge using self.env.cr
and work fine because that cursor have a delete.
But all tests use rollback
at final.
Then you will have a dirty database with a module called: database_cleanup_test
I mean, without this patch
cursor_x
BEGIN;
INSERT INTO ir_module_module
COMMIT;
END;
self.env.cr
BEGIN;
.... # many other transactions
DELETE FROM ir_module_module
ROLLBACK;
END;
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I see. Well, it's not beautiful, but I don't think it's worth the time to get this cursor's commit patched away to by starting a patch fest of the involved methods. Ignore this comment then
@@ -87,11 +87,15 @@ def purge(self): | |||
pass | |||
except AttributeError: | |||
pass | |||
if line.name not in self.env: |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
do we need this now that the test runs at the end of everything? The problem is that for the actual use case of the module, this will happen very often, and reloading the registry for every unknown model will take very long. The alternative would be to check for the testing flag and do it only then if it's still necessary for the test
self.env['ir.model'].browse([row[0]])\ | ||
.with_context(**context_flags).unlink() | ||
model = self.env['ir.model'].browse([row[0]]) | ||
if line.name in self.env: |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
this defeats the purpose of purging undefined modules
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I know but I didn't find the way to fix the issue (I revert this change to see the error from travis):
======================================================================
ERROR: test_database_cleanup (openerp.addons.database_cleanup.tests.test_database_cleanup.TestDatabaseCleanup)
Traceback (most recent call last):
` File "/root/build/OCA/server-tools/database_cleanup/tests/test_database_cleanup.py", line 58, in test_database_cleanup
` purge_models.purge_all()
` File "/.repo_requirements/odoo/openerp/api.py", line 248, in wrapper
` return new_api(self, *args, **kwargs)
` File "/root/build/OCA/server-tools/database_cleanup/models/purge_wizard.py", line 51, in purge_all
` self.mapped('purge_line_ids').purge()
` File "/.repo_requirements/odoo/openerp/api.py", line 248, in wrapper
` return new_api(self, *args, **kwargs)
` File "/root/build/OCA/server-tools/database_cleanup/models/purge_models.py", line 94, in purge
` model.with_context(**context_flags).unlink()
` File "/.repo_requirements/odoo/openerp/api.py", line 248, in wrapper
` return new_api(self, *args, **kwargs)
` File "/.repo_requirements/odoo/openerp/api.py", line 574, in new_api
` result = method(self._model, cr, uid, self.ids, *args, **old_kwargs)
` File "/.repo_requirements/odoo/openerp/addons/base/ir/ir_model.py", line 147, in unlink
` model.field_id._prepare_update()
` File "/.repo_requirements/odoo/openerp/api.py", line 248, in wrapper
` return new_api(self, *args, **kwargs)
` File "/.repo_requirements/odoo/openerp/addons/base/ir/ir_model.py", line 445, in _prepare_update
` model = self.env[record.model]
` File "/.repo_requirements/odoo/openerp/api.py", line 768, in __getitem__
` return self.registry[model_name]._browse(self, ())
` File "/.repo_requirements/odoo/openerp/modules/registry.py", line 84, in __getitem__
` return self.models[model_name]
` KeyError: u'x_database.cleanup.test.model'
To show the error ====================================================================== ERROR: test_database_cleanup (openerp.addons.database_cleanup.tests.test_database_cleanup.TestDatabaseCleanup) Traceback (most recent call last): ` File "/root/build/OCA/server-tools/database_cleanup/tests/test_database_cleanup.py", line 58, in test_database_cleanup ` purge_models.purge_all() ` File "/.repo_requirements/odoo/openerp/api.py", line 248, in wrapper ` return new_api(self, *args, **kwargs) ` File "/root/build/OCA/server-tools/database_cleanup/models/purge_wizard.py", line 51, in purge_all ` self.mapped('purge_line_ids').purge() ` File "/.repo_requirements/odoo/openerp/api.py", line 248, in wrapper ` return new_api(self, *args, **kwargs) ` File "/root/build/OCA/server-tools/database_cleanup/models/purge_models.py", line 94, in purge ` model.with_context(**context_flags).unlink() ` File "/.repo_requirements/odoo/openerp/api.py", line 248, in wrapper ` return new_api(self, *args, **kwargs) ` File "/.repo_requirements/odoo/openerp/api.py", line 574, in new_api ` result = method(self._model, cr, uid, self.ids, *args, **old_kwargs) ` File "/.repo_requirements/odoo/openerp/addons/base/ir/ir_model.py", line 147, in unlink ` model.field_id._prepare_update() ` File "/.repo_requirements/odoo/openerp/api.py", line 248, in wrapper ` return new_api(self, *args, **kwargs) ` File "/.repo_requirements/odoo/openerp/addons/base/ir/ir_model.py", line 445, in _prepare_update ` model = self.env[record.model] ` File "/.repo_requirements/odoo/openerp/api.py", line 768, in __getitem__ ` return self.registry[model_name]._browse(self, ()) ` File "/.repo_requirements/odoo/openerp/modules/registry.py", line 84, in __getitem__ ` return self.models[model_name] ` KeyError: u'x_database.cleanup.test.model'
0152b5e
to
a76e783
Compare
@moylop260, please rebase that I have fixed 2 small PEP8 problems. |
self.env.cr.execute( | ||
'insert into ir_attachment (name, res_model, res_id, type) values ' | ||
"('test attachment', 'database.cleanup.test.model', 42, 'binary')") | ||
self.registry.models.pop('x_database.cleanup.test.model') | ||
self.registry._pure_function_fields.pop( | ||
'x_database.cleanup.test.model') | ||
self.registry.setup_models(self.env.cr, partial=False) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
right, doing this actually makes this a good model, so the next line fails because there's nothing to purge. Just pop the model from the registry immediately, then this goes well
….model' Traceback (most recent call last): ` File "~/build/OCA/server-tools/database_cleanup/tests/test_database_cleanup.py", line 65, in test_database_cleanup ` purge_models.purge_all() ` File "~/build/OCA/server-tools/database_cleanup/models/purge_wizard.py", line 51, in purge_all ` self.mapped('purge_line_ids').purge() ` File "~/build/OCA/server-tools/database_cleanup/models/purge_models.py", line 94, in purge ` .with_context(**context_flags).unlink() ` File "~/odoo/openerp/api.py", line 574, in new_api ` result = method(self._model, cr, uid, self.ids, *args, **old_kwargs) ` File "~/odoo/openerp/addons/base/ir/ir_model.py", line 147, in unlink ` model.field_id._prepare_update() ` File "~/odoo/openerp/addons/base/ir/ir_model.py", line 445, in _prepare_update ` model = self.env[record.model] ` File "~/odoo/openerp/api.py", line 768, in __getitem__ ` return self.registry[model_name]._browse(self, ()) ` File "~/odoo/openerp/modules/registry.py", line 84, in __getitem__ ` return self.models[model_name] ` KeyError: u'x_database.cleanup.test.model' 2016-11-18 12:53:24,269 11158 INFO moy42 openerp.addons.database_cleanup.tests.test_database_cleanup: Ran 1 test in 2.599s FAILED
@hbrunn IMHO this is a real issue from openerp/addons/base/ir/ir_model.py#L147 But here we don't have a model in environment. |
That line is not exists from 8.0 version then if I comment this one the test pass fine! Then we should create a fix to odoo/odoo before. It mean that |
We have false red builds by this issue. IMHO we should avoid the false red for other builds with this PR |
@hbrunn what's the status here? Is this good for merging to get the 9.0 branch green? |
Syncing from upstream OCA/server-tools (10.0)
For the merger: I @moylop260 authorize a
squash and merge
here in order to leave the commits comments like as history.