summaryrefslogtreecommitdiff
path: root/odoo/modules/loading.py
AgeCommit message (Collapse)Author
2020-07-27[IMP] core: reporting after testsXavier Morel
Currently there are a few issues with testing reporting (at the command-line): 1. there is a global report after at_install tests, but it gets "scrolled off" by long post_install tests, and is thus easy to miss 2. with test tags, it's easy to fat finger a typo and run 0 tests, which look like everything's running fine (no failure) To improve this, print a global report at shutdown (in `--stop-after-init` mode if tests are enabled) which recapitulates the test results *and prints a warning if no tests were run at all*. Also update the reporting collection to make this more reliable: * have `run_unit_tests` return `None` if it has run no tests, the assertion reporting machinery counts this as neither success nor failure which is exactly what we want * have load_test only report a success *if files were actually loaded* (by having `load_data` return that information) Task 2301268 closes odoo/odoo#54812 Signed-off-by: Xavier Morel (xmo) <xmo@odoo.com>
2020-07-09[IMP] tests: allow to run at_install tests without updateXavier-Do
Debugging/improvement of an at install test may be tedious because of the need to update the module, spending most of the time checking tables and xml file. 1. This commit proposes to allow to execute test without installing or updating a module. The test is still executed during the loading, and the behavior should be close to an execution of tests during an update. Co-authored-by rco-odoo <rco@odoo.com> 2. keep previous behavior if -i or -u is given Three solutions were possible: - The clean one that changes dev habits. When test-enable or test_tags is given, all tests are always executed, a test_tags is needed to select tests to execute: Example: `-u module --test_enable` becomes `-u module --test-tags /module` to keep the same behaviour This solution is the simplest, and executed tests does not depends on database already installed modules. - The conservative solution. When giving -i or -u, the behavior stays the same as before. When giving test-enable without -i/-u, test are executed on all installed modules. - The intermediate solution: When no test_tags is given but a -i and -u is given, only the given modules are tested. This is quite close to the second solution except that a -i module on a new database won't test all dependencies on the first install. The chosen solution is the second one to minimize changes on dev old habits, only an almost unused feature is impacted: using test-enable without any -i or -u. Before this pr only post install tests were executed in this case. Now at_install tests are also executed. This combination is actually used by runbot to execute post_install test in parallel, but a `--test-tags -at_install` tag is given so nothing to worry about here. closes odoo/odoo#53499 Signed-off-by: Raphael Collet (rco) <rco@openerp.com>
2020-04-03[IMP] ir.ui.view: call _update_user_groups_view() once per installRaphael Collet
This saves 1.5% of the total installation time. X-original-commit: afd39e1a9824252d13823e484c60ad813b9b51a6
2020-04-03[IMP] modules: don't mark all packages as 'update' unless necessaryRaphael Collet
When installing a database from scratch, marking all packages (in the module graph) as 'update' forces the migration manager to retrieve all migrations scripts... for nothing. X-original-commit: fd8f3c73c8c30162034c7712fa0993e2408fba89
2020-03-16[IMP] core: improve module loading logsXavier-Do
Performances from a general point of view can be difficult to track. This commit proposes to improve logs in two ways: The current logs only use the sql_counter, wich will only be updated when a cursor is closed. In a test-enable install, this counter is actually the queries of the tests wince the install cursor is open untill the end. The first fix is to use bot sql_counter and sql_log_count to have total queries untill now on closed cursor, but also the current number of queries of the current cursor. This means that the new log format will be {nb} modules loaded in {time}, {loading_querie} (+{test_cr_queries}) queries instead of {nb} modules loaded in {time}, {tests_cr__queries}queries Nothe that in the current version, {nb} is actually the total number of loaded modules until now. This commit also add an equivalent end log by module and change the loglevel of module start on install (mainly usefull if an error occurs before anything else is logged hidding the module causing this error.) A cleaner runbot logger is also added, in order to be abble to call _logger.runbot( instead of _logger.log(25. This will clarify the purpose of such a log level. closes odoo/odoo#47283 Signed-off-by: Christophe Monniez (moc) <moc@odoo.com>
2020-03-12[FIX] core: do not nag about dependencies for modules to removeAdrian Torres
Before this commit: - Install a module - Uninstall the previously installed module - The registry will complain that some dependencies may be missing for the module being uninstalled This happens because we check after the installation / upgrade of modules that none have been left in a transient state to verify that new dependencies have been properly installed and loaded, this applies to 'to install' and 'to upgrade' states however it's not the same for 'to remove' states, as the process of uninstall happens much later in the code. After this commit, simply uninstalling modules will not trigger this error log. Do note that in case of a problem with an uninstall, the function "reset_module_states" will tackle the case of leftover transient states. closes odoo/odoo#47495 X-original-commit: c095a28314f78d1d9854e5e9bcb26014922a4f12 Signed-off-by: Xavier Dollé (xdo) <xdo@odoo.com>
2020-02-12[FIX] core: delay of constraints in upgradeRaphael Collet
Sometimes, constraints are not delayed during a module upgrade: the module is 'to upgrade' but in 'init' mode :-/ Fix this by relying on the module's state only. closes odoo/odoo#45179 X-original-commit: 878b6538961a9b6a5fe1c6ac68d4ff39391abcdf Signed-off-by: Xavier Dollé (xdo) <xdo@odoo.com>
2020-02-12[FIX] core: flush env after pre upgrade scriptsXavier-Do
In some case, a pre-migration script calls `xml_import.parse` to force reload a no-update data in pre-script. It is possible that fields are marked to recompute in the process. The problem is that the reference to the field added in `env.all.tocompute` won't be the same as the reference of the same field after calling `registry.setup_models()`, leading to an infinite loop while recomputing this field, since `fields.__get__` wont find `self` in `env.all.tocompute`. This problem was discovered when trying to migrate a database with all modules installed (no demo data) from 12.0 to 13.0 (for commit references: http://runbot.odoo.com/runbot/build/1176576 with database comming from http://runbot.odoo.com/runbot/build/1171714). This commit adds a check before executing `registry.setup_models()` in order to log when some fields to compute remain before breaking fields references, and adds a `flush()` after pre-scripts to fix the current issue. X-original-commit: 41b9d810066774736c4077bba1dc9c9fba004f48
2020-02-06[FIX] core: delay constraint application in case of upgradeAdrian Torres
closes odoo/odoo#44800 Co-authored-with: Xavier Dollé <xdo@odoo.com> X-original-commit: bc2bb5e03c2b32d4ee1b0597ea5889c17d2b0e0e Signed-off-by: Xavier Dollé (xdo) <xdo@odoo.com>
2020-02-04[IMP] base: use ir.model.access on transient modelsMartin Trigaux
Before this commit models with the `_transient` flag were ignored in ir.model.access verifications. Only an implicit ir.rule with the domain (create_uid=user.id) was applied to avoid most side effects. The problem is that, often, the security does not lie in side-effects of abusing of somebody else's wizard record but in the fact that the wizard methods blindly trust only the right users are creating these records. Too often, too many sudo were used and creating wizard with chosen values could lead to an abuse scenario. Instead, explicitly require the developer to declare security rules the same way as on any other model.
2020-01-24[FIX] core: ignore studio_customization when checking modules statesXavier-Do
Studio customization is an exception, a data module added to ir_module but that is never added to graph since there is no manifest. OPW #2180885 closes #43880 closes odoo/odoo#43940 X-original-commit: 4051ac83b5e7cc1cb91a264b51401ad5601ad4e2 Signed-off-by: Xavier Dollé (xdo) <xdo@odoo.com>
2020-01-22[IMP] core: do not log error for unmet dependencies on add_modulesXavier-Do
When migrating a database, load_marked_modules will be called multiple times, alternating to upgrade and to install modules. The main reason for this is still a litle confusing but it as the side effect to log "Unmet dependencies" error multiple time in add_modules, even if the dependency will be resolved later. This commit removes the error level for this log, and replace it by another check, performed at the end, logging any module in "to install"/"to upgrade" state. Also log removed module as info (25), not warning. This may be changed latter closes odoo/odoo#43797 X-original-commit: c5d6a3977de85fb974a4940fb11d54ef847e08e4 Signed-off-by: Xavier Dollé (xdo) <xdo@odoo.com>
2019-08-26[FIX] sql_db: add flush() in savepoint()Raphael Collet
closes odoo/odoo#36060 Signed-off-by: Raphael Collet (rco) <rco@openerp.com>
2019-08-20[IMP] models: ORM speedupRaphael Collet
This branch is the combination of several optimizations in the ORM: * store field values once in the cache: the cache reflects more faithfully the database, only fields that explicitly depend on the context have an extra indirection in the cache; * delay recomputations by default: use method `recompute` to explicitly flush out pending recomputations; * delay updates in method `write`: updates are stored in a data structure that can be flushed efficiently to the database with method `flush` (which also flush out recomputations); * make method `modified` take advantage of inverse fields to inverse dependencies; * filter records by evaluating a domain on records in Python; * a computed field with `readonly=False` behaves like a normal field with an onchange method; * computed fields are computed in superuser mode by default. Work done by Toufik Ben Jaa, Raphael Collet, Denis Ledoux and Fabien Pinckaers. closes odoo/odoo#35659 Signed-off-by: Denis Ledoux <beledouxdenis@users.noreply.github.com>
2019-08-14[MERGE] forward port branch saas-12.4 up to 98a55917a60Christophe Simonis
2019-07-25[FIX] core: auto_install modules being very stickyXavier Morel
An unintended side-effect of #29431 is apparently that auto_install applications automatically get reinstalled when uninstalled, which was not the goal. Move the auto_install selection back into db.py, this version seems to work even though the previous attempt was apparently unsuccessful. closes odoo/odoo#35180 Signed-off-by: Xavier Morel (xmo) <xmo@odoo.com>
2019-07-25[IMP] core: improve test logsXavier-Do
1. Make test logs clearer & remove redundancies Instead of having an ERROR log right when the test fails then print the useful / relevant information at the end of the test suite, immediately print the traceback. Keep the final summary. Also avoids having to wait for the entire test suite to end before a dev' can know the failure details of a specific test. Done by working at a lower level and replacing the custom test stream mess by a custom Result class which prints and formats the information we want. Replace TextTestRunner by a bare-bones custom Runner object to tie it in. 2. Provide useful location information on test failure Leverage the work above to log the test function's failure location: previously logging would point to within TestStream which is not useful. Here, on failure the traceback is used to discover the caller info and point to the test line which fails instead. similar to unittest's _exc_info_to_string (https://github.com/python/cpython/blob/93e8aa62cfd0a61efed4a61a2ffc2283ae986ef2/Lib/unittest/result.py#L173). 3. Replace direct logging in browser_js by raising errors Properly marks the test as in error, and the error traceback points to the tour definition / launcher (python side) rather than common.py and/or module.py. Also removes unused dbname parameter that was added in /278ed718e9805edf088642ba10d3b7c4e5716c31/openerp/modules/module.py#L361 for nor visible reason closes odoo/odoo#34996 Signed-off-by: Xavier Morel (xmo) <xmo@odoo.com>
2019-05-22[IMP] loading: tests are allowed without demo dataChristophe Monniez
As most of the tests are using demo data, a check is performed to verify that they are loaded. A best practice is to write tests that does not depend on demo data but with this check, it's not possible to launch them without demo data. With this commit, the check is removed, allowing to launch test even without demo data loaded. closes odoo/odoo#33531 Signed-off-by: Christophe Monniez (moc) <moc@odoo.com>
2019-05-07[IMP] core: allow auto_install restriction on a subset of dependenciesXavier Morel
Currently, auto_install is triggered when all dependencies get installed, but there are cases where one would want such trigger on only a subset thereof. e.g. we want `website_sale_dashboard` to auto-install when `website_sale` is installed. Currently, it requires `web_dashboard` to also be auto-installed otherwise `website_sale_dashboard` would "wait" for both dependencies to be explicitly installed before the auto-install triggers. That's despite `web_dashboard` not being very useful on its own. More generally this is an issue with technical modules which need to be marked as auto_install so as not to block e.g. bridge modules from automatically installing. This change allows setting `auto_install` to a subset of `depends`: * if auto_install is set to `False`, the module does not get automatically installed (no change in semantics) * if auto_install is set to `True`, the module gets automatically installed if and only if all its dependencies are installed (also no change in semantics) * if auto_install is set to a list of dependencies, the module will be installed when all *these* dependencies are installed, other dependencies (excluded from auto_install) will be installed alongside as a consequence * auto_install can be set to an empty list, in this case the module will always be automatically installed regardless of its dependencies (and will force their installation). So after this change, `web_dashboard`'s auto_install can be set to `False` (such that it's not installed if no module defining dashboards is installed) and `website_sale_dashboard`'s manifest can be edited to: 'auto_install': ['website_sale'] possibilities: # no automatic installation 'depends': ['a', 'b'], 'auto_install': False # automatic installation if both a and b are installed 'depends': ['a', 'b'], 'auto_install': True # automatic installation if both a and b are installed (explicit) 'depends': ['a', 'b'], 'auto_install': ['a', 'b'] # automatic installation if b is installed, a will get forcefully # installed if it isn't yet 'depends': ['a', 'b'], 'auto_install': ['b'] # always automatically installed, will cause the installation of # its dependencies even if they're not marked explicitly 'depends': ['a', 'b'], 'auto_install': [] Task 1851328 closes odoo/odoo#29431 Signed-off-by: Xavier Morel (xmo) <xmo@odoo.com>
2018-11-22[FIX] odoo: ormcache invalidation on loading registryRaphael Collet
Do not propagate cache invalidations to other workers when simply loading the registry. Only do it when installing/upgrading/uninstalling modules.
2018-10-19[FIX] loading: set dbdemo if demo install successAdrian Torres
opw-1896028 closes odoo/odoo#27945
2018-09-25[FIX] ir_ui_view: do not check arch twice upon install/upgradeRaphael Collet
After a module upgrade, validate the architecture of the module's views that are impacted by updates, but have not been checked yet. Before this patch, views were checked twice on average. This patch speeds up the installation of modules by about 15% without demo data. With demo data, the speedup is around 10%.
2018-09-24[IMP] core: require install mode for db bootstrapOlivier Dony
The registry loading system should not alter databases unless it is asked to do so, by a module installation or update instruction. This property should hold true as well for database bootstrap, and this is what this commit changes.. In order to avoid any behavior change for command-line users, an implicit `-i base` is assumed when starting the server from the command-line with `-d <db>`, causing the db boostrap to happen if the database did not exist yet.
2018-08-01[MERGE] forward port branch saas-11.4 up to 8d9366197e1Christophe Simonis
2018-07-23[MERGE] forward port branch 11.0 up to 219d2296d67Christophe Simonis
2018-07-23[MERGE] forward port branch saas-15 up to c4ee29345a6Christophe Simonis
2018-07-23[MERGE] forward port branch saas-14 up to 9ee882564f6Christophe Simonis
2018-07-23[MERGE] forward port branch 9.0 up to af2e480e419Christophe Simonis
2018-07-16[IMP] base: disable demo data if they can't installXavier Morel
Task 1856935 Currently, if installing a module's demo data fails (because the module was uninstalled and some were left over and can't be reinstalled, or because they're broken, or…) the installation of the module fails and further installations are skipped (?). Since demo data are non-essential (though required to run tests), rather than fail everything if they fail just roll them back and notify the user. This change generates a warning log *and* shows a notification popup to the end user.
2018-07-16[IMP] de-commit-ify db/module installXavier Morel
Try to remove cr.commit (and rollback) from module and db install: * put a savepoint around test data loading * remove a bunch of commits sprinkled throughout * remove rollback on data loading failure (assuming it bubbles up, the entire module's installation should be rolled back) * add commit right before the tests are run, so they can run isolated and still see whatever was done when installing their module * convert a few explicit closing to context managers
2018-07-11[IMP] allow installing demo data post db initAdrian Torres
Intended for demo / throwaway databases only Task-ID: 1856493
2018-07-05[MERGE] forward port branch 11.0 up to 84210074e55Christophe Simonis
2018-07-05[MERGE] forward port branch saas-15 up to b06c09db604Christophe Simonis
2018-07-05[MERGE] forward port branch saas-14 up to 92e5da6b8fdChristophe Simonis
2018-07-05[MERGE] forward port branch 9.0 up to b5c50fa824aChristophe Simonis
2018-06-05[MERGE] forward port branch 11.0 up to 1b272a20504Christophe Simonis
2018-06-05[MERGE] forward port branch saas-14 up to a002210d930Christophe Simonis
2018-06-05[FIX] orm: re-create constraints of extended fieldsAdrian Torres
Before this commit: * Module A defines a field X of model M * Module B inherits from model M without touching field X * Module C inherits from model M and extends field X by giving an INDEX / NOT NULL constraint. * Module B and C depend from Module A, but not each other If all three modules are installed and Module B is updated, the INDEX / NOT NULL constraint could be dropped. This happens because Module B can be loaded before Module C is loaded, if that's the case, then after the upgrade of Module B, during the schema checking, we verify that the field object we have and the field on the DB are the same, since Module B doesn't introduce the index then this check is false and we drop the index. When we get to loading Module C, we do not do any schema checking because the module is not marked as `to upgrade`, therefore the index is lost forever. To solve this, we re-init the models that belong to the set of the intersection between upgraded and modified models and loaded and modified models. Fixes #24958
2018-06-01[FIX] orm: re-create constraints of extended fieldsAdrian Torres
Before this commit: * Module A defines a field X of model M * Module B inherits from model M without touching field X * Module C inherits from model M and extends field X by giving an INDEX / NOT NULL constraint. * Module B and C depend from Module A, but not each other If all three modules are installed and Module B is updated, the INDEX / NOT NULL constraint could be dropped. This happens because Module B can be loaded before Module C is loaded, if that's the case, then after the upgrade of Module B, during the schema checking, we verify that the field object we have and the field on the DB are the same, since Module B doesn't introduce the index then this check is false and we drop the index. When we get to loading Module C, we do not do any schema checking because the module is not marked as `to upgrade`, therefore the index is lost forever. To solve this, we re-init the models that belong to the set of the intersection between upgraded and modified models and loaded and modified models. Fixes #24958
2018-03-20[MERGE] forward port branch 11.0 up to 2835d299792Christophe Simonis
2018-03-13[FIX] registry, loading: re-init inherited SQL viewsAdrian Torres
Before this commit: * Install any module that creates a SQL view and another that extends this view. e.g.: sale and pos_sale for `report.all.channels.sales`. * Uninstall the module that extended the SQL view. e.g.: uninstall pos_sale. * Try to access the view from the web client -> Traceback, table not found. This happens because when reloading the registry, postgres drops the sql view and it must be re-initialized. After this commit: We solve this issue by calculating all missing tables/views during the uninstallation process, and re-initializing all of them right before reloading the registry. Also remove sql-view hacks in the modules `sale` and `sale_margin`. Fixes #23528, #23529, #23530
2018-01-18[REM] config, loading: remove test-commit and test-report-directoryChristophe Monniez
As there are few use cases for the --test-commit and --test-report-directory options, they are removed.
2017-12-06[MERGE] forward port branch 11.0 up to f96a797fe62Christophe Simonis
2017-12-06[MERGE] forward port branch saas-16 up to b8540eefe3bChristophe Simonis
2017-12-04[MERGE] forward port branch saas-15 up to a447da75fd6Christophe Simonis
2017-12-04[MERGE] forward port branch saas-14 up to e7d174a1422Christophe Simonis
2017-12-01[FIX] *: Reset module states on registry init errorAdrian Torres
Commit 763d714 introduced cron job locking for databases which had modules with states set to 'to x', however if an installation/uninstallation/upgrade fails, the state will stay at 'to x', and it may stay in that state for an indefinite amount of time, meaning that cron jobs could stay locked forever. This commit fixes this in part by adding a cleanup function to loading.py that will be executed whenever load_modules fails, the function will change every 'to x' module to their original state, effectively unlocking the execution of cron jobs. This however only works to prevent "zombie" transient states for brand new databases, however for existing databases which already contain some modules in a zombie state it won't do anything unless a module is installed/uninstalled/upgraded, which may never happen. This is where the second part comes in (ir_cron.py), when failing to execute crons, we check if the failure was due to bad module state and if an arbitrary amount of time (5 hours as of this commit) has passed since the last time it was supposed to be executed, if it is the case, it means that the cron execution failed around 5 * 60 times (1 failure per minute for 5h) in which case we assume that the crons are stuck because the db has zombie states and we force a call to reset_module_states.
2017-11-16[REM] tools: Remove the yml import engineYannick Tivisse
2017-10-09[FIX] loading: Don't add None to installed apps (#19850)Adrian Torres
Previous to this rev., sometimes None could be added to the list of _init_modules in the registry, this would then be problematic in ir_http since a sorted would be performed on this list, which works in py2 but in py3 None and string can't be compared implicitly.
2017-10-02[MERGE] forward port branch saas-16 up to b3d0897f2d8Christophe Simonis