Commit Graph
18 Commits
Author SHA1 Message Date
Renaud Thiry dddb2f5355 [IMP] base: Clear precommits on test cleanup
Precommit hooks would stock data until a call to ``cr.flush`` was made.
Notably, this happens when the ``assertRaises`` method is called.
Functions were applied on records already cleared from the cache.

This change adds a cleanup call for `TransactionCase` as it keeps
the same cursor for all tests. Cursor precommits can now
be safely executed inside tests.

Task-2834304

Forward port of #117555

closes odoo/odoo#118290

X-original-commit: ff5d0c75fcea5842c5236b1b3f7480ef5a3dc415
Signed-off-by: Thibault Delavallee (tde) <tde@openerp.com>
Signed-off-by: Thiry Renaud (reth) <reth@odoo.com>
2023-04-13 04:08:25 +02:00
bve-odoo 708f5997c5 [FIX] core: recycle more connections in multi-tenant servers
During revision 415525cecc
the code comparing the connections without password has been
dropped, for an unknown reason.

Because of the above, and the fact psycopg2 alter the password
with 'xxx' for security reasons, the connections recycling was
no longer working as expected, and was recycling less connections.

closes odoo/odoo#37005

Signed-off-by: Rémy Voet <ryv@odoo.com>
2023-02-20 12:19:19 +01:00
Rémy Voet (ryv) 37a9a2e166 [REM] sql_db.py: clean file and our Cursor class
- Remove `_default_log_exceptions` of our `Cursor` class (unused except
in one test)
- Deprecated `serialized` args of `__init__` (Cursor class) and
`cursor()` (of Connection class), our cursor is always serialized.
- Remove `sql_log` attribute of Cursor class and replace it with
appropriate code to do the same stuff dynamically.
- Simplify some code
- Update some docstring
- Clean import

task-2766494

closes odoo/odoo#85078

Signed-off-by: Rémy Voet <ryv@odoo.com>
2022-09-09 11:11:59 +02:00
Rémy Voet (ryv) db76b065ee [FIX] sql_db.py: fix error type raised by closed cursor
Since e014cc88394fb9c8f6cff556ca73d5efafea030f, our proxy
`Cursor` object doesn't return a understandable error when we
try to use it when it is already closed
(`NoneType` or `Recursion` error).

Instead of reverting e014cc88394fb9c8f6cff556ca73d5efafea030f,
add a check in `__getitem__` raising a IterfaceError (like psycopg)
if we try to use psycopg cursor (`self._obj`)

task-2766494

Part-of: odoo/odoo#85078
2022-09-09 11:11:58 +02:00
Raphael Collet 9c3b9a4926 [FIX] core: automatically flush upon invalidation for cache consistency
Because method _read() no longer updates existing values in memory,
those values in memory must be consistent with the database.

On the other hand, if pending updates are not performed on the database
before fetching values, it means that the corresponding database values
cannot be put in cache.  This implies that one cannot empty the cache
without flushing the corresponding fields.

In order to avoid mistakes, flush automatically before invalidating the
cache.  This makes the invalidation methods safe by default, and avoids
cargo-culting which would systematically associate invalidation to
flushing, which may eventually be less performant.

Part-of: odoo/odoo#66938
2022-07-05 11:35:00 +02:00
Raphael Collet 60a1452a40 [REF] base: adapt code to new flush API
Part-of: odoo/odoo#87527
2022-05-25 18:00:47 +02:00
Xavier Morel 70dabd5661 [IMP] core: add TestCursor warning when finding unclosed test cursor
Because test cursors are implemented using savepoints, they should *at
most* be nested (ideally they would be strictly sequenced).

If upon being closed a test cursor finds a *different* un-closed
cursor at the top of the stack, one of its followers / children /
descendants was not closed before it, which is a problem.

The initial version of this would look for the cursor being closed in
the stack but this could lead to incoherent cursor stacks and errors
related to the management of the cursors stack, even though it only
exists for reporting reasons.

closes odoo/odoo#76243

Signed-off-by: Xavier Morel (xmo) <xmo@odoo.com>
2021-10-01 15:26:51 +00:00
Raphael Collet 765ec7837c [REF] core: add methods flush() and clear() on cursor
This deprecates the ugly and inconvenient functions flush_env(),
clear_env(), and avoids explicit calls to precommit.run().

Part-of: odoo/odoo#75598
2021-09-03 15:45:46 +00:00
Raphael Collet 3e77accdc3 [FIX] base: tests on test cursor 2020-11-24 13:23:32 +00:00
Laurent Mignon (ACSONE)andRaphael Collet 868311392c [FIX] core: Ensure that rollback hooks are called when the cursor is closed
Before this change the rollback hooks were never called since rollback() was never explicitely called by the framework. At the end of a transaction, if no error occurs the famework call commit() on the odoo cursor. In all cases, the transaction ends with a call to close(). Into the implementation of _close()  rollback() is called on the underlying connection to ensure that not committed changes are rollbacked. That's the reason why despite the fact that rollback() was not called on the Odoo cursor, changes are not committed into the db in case of exception. To keep the same behaviour and avoid to have to explicitely call rollback() on the odoo cursor to trigger the execution of registered rollback hooks, these hooks are now processed in _close(). Since the list of registered hooks is emptied if commit() is called, we are sure that rollback hooks are only executed in case of rollback.

OPW #2294911

closes odoo/odoo#60339

X-original-commit: dce9a05f3a5d37fab711c8ca3c5444941f98e814
Signed-off-by: Raphael Collet (rco) <rco@openerp.com>
Co-authored-by: Raphael Collet <rco@odoo.com>
2020-10-20 09:08:36 +00:00
Raphael Collet 9920f20e4c [IMP] models: ORM speedup
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-20 12:43:59 +00:00
Xavier-Do 95b4f2ab4b [IMP] core: improve test_tags
Add the support to be able to specify exlicitely module, class and method name in test_tags

Before this commit, there is no distinction between module tag and test tag. Meaning
that --test-tag module_name will replace the default +standard tag and execute all test
of the module.

This commit tries to keep the initial behaviour, while addind new features, like explicit
modules tag with /module_name, as well as class (:class) and method (.method)

Some usage examples:
--test_tags /module will execute all standard test of module
--test_tags :class will execute all standard test with class name 'class'
--test_tags .method will execute all standard test with method name 'method'
--test_tags external/module will execute all external test of module
--test_tags */module will execute all tests of module,
--test_tags */module,-standard will execute all non standard tests of module,
--test_tags -/website:TestUiTranslate.test_admin_tour_rte_translator will disable only rte translator test

closes odoo/odoo#34756

Signed-off-by: Raphael Collet (rco) <rco@openerp.com>
2019-07-11 09:03:14 +00:00
Christophe Simonis 0c42a607ec [FIX] base: correct TestCursor test to explicitly close the cursor 2019-02-05 18:38:19 +01:00
Christophe Simonis 9c6acbaaa0 [MERGE] forward port branch 11.0 up to e0b14bf9a7 2019-02-05 17:53:35 +01:00
Raphael Collet 266f99f545 [FIX] tools: use of savepoints in TestCursor
closes odoo/odoo#30768
2019-02-01 14:09:38 +00:00
Christophe Monniez b356b19033 [IMP] tests: Add the possibility to tag tests
Purpose: When running tests, all the tests for the installed/updated
files are done. This commit adds a 'tagged' decorator that can be used to
tag tests. Combined with a new 'test-tags' CLI option, it adds the ability
to filter which tests are executed. For example, @tagged('slow') will
add a tag 'slow' to the test. The CLI option 'test-tags="slow"' will
only run tests tagged 'slow'.

One can use prefixes to select cases with tags.
'+' or no prefix means that the tests tagged with this tag are selected
for execution. '-' prefix will exclude the tests tagged with this tag.
Exclusion takes precedence over inclusion.

Also, by default, all Odoo tests cases are tagged 'standard' and with
the technical name of the module.
This means that when selecting tests with the 'test-tags'
parameter, if '-standard' is not specified, all tests tags are
going to be executed.
When tagging tests, one can remove such automatic tag by prefixing the
tag name with '-'. E.g. @tagged('-standard') will remove the standard
tag from the test.

Another example, if one wants to test the 'sale' module alone,
even without adding any 'tagged' decorator thos tests can be selected
like that: --test-tags="sale"

Tests are selected or deselected using a TagsSelector. When instanciated,
 a string is passed with comma separated tests selectors like
'+slow,-standard'. When the 'check' method is called  with a test as argument,
it returns True or False if the test has to be executed or not.
2018-01-18 13:20:37 +01:00
Raphael Collet 0783318f97 [FIX] adapt logger names 2016-09-02 17:28:13 +02:00
Raphael Collet 9e64f9f951 [REF] openerp: move openerp to odoo 2016-09-02 17:28:12 +02:00