Commit Graph
62 Commits
Author SHA1 Message Date
Raphael Collet 5560ac4a04 [FIX] models: generalize the protection mechanism to not recompute some fields
The protection prevents fields to be invalidated/recomputed on some records.
This mechanism is useful against accidental cache invalidation when computing
or inversing fields.  It also prevents to trigger the recomputation of fields
before and/or after their inversion.

Add a test on stored field with compute and inverse methods: the test checks
how many times the compute and inverse methods are invoked in several cases.
Essentially, the field should not be recomputed when it is written.
2016-07-01 10:49:27 +02:00
Raphael Collet 4edcba696e [IMP] api: make Environment implement the Mapping API 2016-06-16 16:50:48 +02:00
Raphael Collet 4f2f1247a6 [IMP] api: make decorator @returns work when model=None
Specifically, the `upgrade` function simply returns the given value.
2016-06-16 16:50:47 +02:00
Raphael Collet 1ec7b28a09 [FIX] models, fields, api: do not mix the cache format with the record format 2016-04-25 13:37:11 +02:00
Raphael Collet 8bc7d8565c [IMP] models: attach prefetching data to recordsets instead of environments
The prefetching now has a more intuitive and controllable model: every
recordset is linked to a "prefetch object" that tells which record ids to
prefetch for any model.  The prefetch object of a given recordset is shared
with the records obtained by iteration and relational field access.  All other
operations instantiate recordsets with a fresh prefetch object.

    records = model.browse(ids)
    assert records._prefetch is not model._prefetch

    for record in records:
        assert record._prefetch is records._prefetch
        assert record.relation._prefetch is record._prefetch
2016-04-25 13:37:11 +02:00
Christophe Simonis 9a805c90ed [MERGE] forward port of branch saas-9 up to d70fde0 2016-02-10 18:40:56 +01:00
Christophe Simonis cab5c480e2 [MERGE] forward port of branch 9.0 up to f7432ef 2016-02-10 18:33:01 +01:00
Christophe Simonis f7432efb95 [MERGE] forward port of branch saas-6 up to 07d7147 2016-02-10 18:17:21 +01:00
Christophe Simonis 07d7147846 [MERGE] forward port of branch 8.0 up to cdf21eb 2016-02-10 18:03:42 +01:00
Raphael Collet 5763c32a6d [FIX] addons: fix usage of decorators api.v7/api.v8
Specifically, when one API implementation calls the other one, it has to call
the method *from the same class*.  Otherwise, overriding the method may result
in an infinite recursion.  Consider:

    class A(Model):
        _name = 'stuff'

        @api.v8
        def foo(self):
            return 42

        @api.v7
        def foo(self, cr, uid, context=None):
            return self.browse(cr, uid, [], context).foo()

    class B(Model):
        _inherit = 'stuff'

        def foo(self, cr, uid, context=None):
            return super(B, self).foo(cr, uid, context=context) + 1

and now call: `env['stuff'].foo()`.  This invokes `B.foo` (new-API), which
calls `B.foo` (old-API), which calls `A.foo` (old-API), which calls `B.foo`
(new-API) instead of `A.foo`!

This issue would not be present if old-API `A.foo` was defined as:

        @api.v7
        def foo(self, cr, uid, context=None):
            return A.foo(self.browse(cr, uid, [], context))
2016-02-09 10:01:43 +01:00
Christophe Simonis 4d6bca4383 [MERGE] forward port of branch saas-9 up to 740a6ea 2016-01-12 18:49:16 +01:00
Christophe Simonis 9ad5c66a44 [MERGE] forward port of branch 9.0 up to 33299fd 2016-01-12 18:47:43 +01:00
Christophe Simonis 33299fd689 [MERGE] forward port of branch saas-6 up to 5eee559 2016-01-12 18:46:23 +01:00
Christophe Simonis 5eee5591ab [MERGE] forward port of branch 8.0 up to 37ed5ce 2016-01-12 18:24:27 +01:00
Sathors 903cde0522 [IMP] doc: dotted names not supported in @constrains
or in @onchange for that matter. They should already generate a warning,
but only the first time they're used.

This is done lazily because it introspects the instance/class which can
be costly when performed during the repeated setup of registry setup.

closes #5595
2016-01-11 10:59:56 +01:00
Raphael Collet 403f23782b [IMP] api: add new decorators model_cr and model_cr_context
Those decorators will be useful for converting to the new API methods that only
take `self`, `cr`, and possibly `context`.
2016-01-08 17:08:39 +01:00
Christophe Simonis d490630745 [MERGE] forward port of branch 9.0 up to b293953 2015-11-25 16:18:10 +01:00
Christophe Simonis 56a442e205 [MERGE] forward port of branch saas-6 up to dade7e3 2015-11-25 13:26:02 +01:00
Christophe Simonis 12d5b4168f [MERGE] forward port of branch 8.0 up to 8e1a5ad 2015-11-25 11:18:21 +01:00
Raphael Collet 8e1a5add38 [FIX] api: improve decorator returns to handle special cases, like method search
Add the possibility in the decorator to specify the `upgrade` and `downgrade`
functions that convert values between APIs.  Both function have the same API:

    upgrade(self, value, *args, **kwargs)
    downgrade(self, value, *args, **kwargs)

The arguments ``self``, ``*args`` and ``**kwargs`` are the ones passed to the
method, following its new-API signature.

Fixes #4944, #7830.
2015-11-25 09:59:35 +01:00
Raphael Collet 946c749660 [IMP] api: add missing symbols in __all__ 2015-11-10 14:47:47 +01:00
Raphael Collet fe4872f10c [IMP] api: add a decorator for old-API methods that take records as parameters
The decorator transforms old-API calls like

    model.method(cr, uid, records, args)

into

    records.method(args)
2015-10-30 14:37:04 +01:00
Denis Ledoux 56ef99d050 [MERGE] forward port of branch saas-6 up to 105b1c0014 2015-10-23 18:31:55 +02:00
Raphael Collet ac98af1e9f [IMP] models: recompute fields following a topological order on their dependencies
The goal is to avoid recomputing field several times.  Consider, for instance,
two fields F and G, such that G depends on F.  Suppose that G is recomputed
before F.  Saving G to database proceeds well, but when F is saved to database,
G is invalidated and marked for recomputation.  Field G is possibly recomputed
twice on some records.

Avoid this situation by chosing a field such that none of its dependencies must
be recomputed; use a topological sort based on field dependencies for that
purpose.  In the example above, G will never be recomputed before F.
2015-10-13 14:49:57 +02:00
Denis Ledoux 105b1c0014 [MERGE] forward port of branch 8.0 up to 25634df 2015-10-05 16:20:13 +02:00
Raphael Collet 446d59fd44 [IMP] api: improve documentation of api.onchange
This fixes #3968.
2015-10-02 11:58:44 +02:00
Christophe Simonis 57168a9e90 [MERGE] forward port of branch saas-6 up to a669433 2015-09-23 14:34:26 +02:00
Denis Ledoux a3648fd23a [MERGE] forward port of branch 8.0 up to aabbdc7 2015-09-21 16:01:58 +02:00
Raphael Collet 7d558a9a86 [IMP] models: improve code to enable field prefetching in onchange mode
Enable the prefetching of several fields while evaluating an onchange.  Special
care is taken to not prefetch computed fields or fields already in cache.  The
latter is necessary to avoid "cleaning up" dirty fields by accident.
2015-09-18 18:12:23 +02:00
Raphael Collet 5805b87005 [IMP] api: in todo list, group records to recompute by environment
The effect of this change is to trigger the recomputation of fields on larger
recordsets.  This takes advantage of batch computations within compute methods.
2015-09-16 11:56:44 +02:00
Xavier Morel 2474a91bc9 [IMP] doc: recommend not using @api.one
* alter docstring of @api.one to mark it as deprecated for 9.0,
  recommend using @api.multi instead
  - deprecation notes were not correctly styled, add styling
    matching "warning" alerts
* move @api.one down the doc page to deemphasize it
* fix "backend" tutorial to remove all instances of ``@api.one``

closes #8527
2015-09-15 14:38:45 +02:00
Raphael Collet 5022891091 [IMP] api: make Environment implement the a mapping API {model_name: model} 2015-08-21 15:40:41 +02:00
Christophe Simonis 2cf91d16a5 [MERGE] forward port of branch saas-6 up to 63e92cb 2015-07-22 16:17:54 +02:00
Christophe Simonis fe92deaa1d [MERGE] forward port of branch 8.0 up to 2de301d 2015-07-07 18:13:57 +02:00
Xavier Morel 95e56a109d [ADD] doc: new theme
Pretty much completely rewritten theme with custom HTML translator and a
few parts of the old theme extracted to their own extensions.

Banner images thought not to be that huge after all, and not worth the
hassle of them living in a different repository.

co-authored with @stefanorigano
2015-07-07 11:22:50 +02:00
Olivier Dony 0bd4545348 [LEGAL] Use global LICENSE/COPYRIGHT files, remove boilerplate text
- Preserved explicit 3rd-party copyright notices
- Explicit boilerplate should not be necessary - copyright law applies
  automatically in all countries thanks to Berne Convention + WTO rules,
  and a reference to the applicable license is clear enough.
2015-06-02 03:16:04 +02:00
Christophe Simonis 0da722aa6a [MERGE] forward port of branch 8.0 up to bff6dff 2015-05-11 15:12:24 +02:00
Denis Ledoux b7f1b9c01e [FIX] models: recompute nested old-style computed field
The `set` method of the one2many class returns a list
of the fields that require recomputation,
the computing of the function fields being delayed
for performances reasons.

Nevertheless, if the `set` method was called
through another `set` method, in other words,
nested `set` calls, the fields to recompute returned
by the second, nested, call to set were never recomputed,
the result list were simply lost.

e.g.:
```
create/write
│set
└─── create/write with recs.env.recompute set to False
    │set
        └─── create
             with recs.env.recompute set to False
```

To overcome this problem, the list of old api style
compute fields to recompute is stored
within the environment, and this list is cleared
each time the store_set_value has done its job of
recomputing all old api style compute fields.

opw-629650
opw-632624
closes #6053
2015-05-06 17:25:44 +02:00
Christophe Simonis 2260496879 [MERGE] forward port of branch 8.0 up to a939a27 2015-05-05 18:48:34 +02:00
Raphael Collet 071152216f [FIX] fields: when computing digits, use an existing cursor instead of a new one
The computation of property `digits` was creating a new cursor to call the
function that determines digits.  This technique is fragile because the current
cursor may have pending updates that the new cursor will not see.

The issue was discovered by Cécile Tonglet (cto).  She observed an infinite
loop during a database migration, and a traceback inside the loop showed the
presence of the `digits` property.  This change fixes the infinite loop issue.
2015-05-05 17:33:16 +02:00
Christophe Simonis 1b3fb3c4a8 [MERGE] forward port of branch 8.0 up to 222b2d3 2015-02-17 18:54:52 +01:00
Denis Ledoux c9154e08aa [FIX] api: environment recomputation
In a workflow context (for instance, in the invoice workflow),
context is not passed.

Therefore, relying on the 'recompute' key being the context
in order to not recompute the fields does not work with Workflows.

It leads to huge performance issues,
as fields are recomputed recursively (instead of sequentially)
when several records are implied.
For instance, when reconciling several invoices with one payment
(100 invoices with 1 payment for instance),
records of each invoice are recomputed uselessly in each workflow call
(for each "confirm_paid" method done for each invoice).

With a significant number of invoices (100, for instance),
it even leads to a "Maximum recursion depth reached" errror.

closes #4905
2015-02-12 14:57:31 +01:00
Christophe Simonis 7f2de62378 [MERGE] forward port of branch 8.0 up to 33a8989 2015-02-11 17:25:33 +01:00
Raphael Collet 4fd8e40ff7 [FIX] fields: add a flag "compute_sudo" to recompute fields as user admin
This reverts commit 8cd2cc8910.

It turned out that forcing recomputing fields as user admin breaks some
existing behavior.  Instead, we make the recomputation as user admin explicit
by adding compute_sudo=True in the field's definition.
2015-02-09 09:57:34 +01:00
Stefan Rijnhart 0fc5860fca [IMP] api decorator allow both res_id as well as id
As in python id is a builtin function name.

Closes: #5027
2015-02-09 01:10:36 +01:00
Christophe Simonis 6f841038f3 [MERGE] forward port of branch 8.0 up to 3735394 2015-01-22 18:47:13 +01:00
Raphael Collet 8cd2cc8910 [FIX] models: recompute fields with user admin to prevent access rights issues 2015-01-22 15:32:18 +01:00
Christophe Simonis 18e22be138 [MERGE] forward port of branch 8.0 up to 0aab81c 2015-01-19 17:15:56 +01:00
Goffin Simon 0fd773a486 [IMP] Cleanup and refactoring of exception handling
Unify and refactor exception handling in framework and addons.

The generic `except_osv` is now deprecated, and replaced by more specialized exception subtypes:
 - `UserError` (renamed from Warning, as it conflicts with the built-in `Warning`) raised when a non-technical error occurs during a business operation. It could be a missing information in the data provided by the user, or a misconfiguration.
 - `AccessError`: raised when any operation is denied because the user conducting it does not have the required access rights.
 - `AccessDenied`: raised when an operation that requires authenticated access is attempted via an unauthenticated request.
 - `MissingError`: raised when an operation is attempted on a record that does not exist.
 - `ValidationError`: raised when an operation violates a SQL or Python constraint.
 - All other exceptions are internal errors due to a system problem or bug, and raised untouched to the client-side, which should display a traceback.

All exceptions take a single message argument.

The `test_exceptions` module has been updated to showcase both new and old (deprecated) exceptions.

A great many old `except_osv` had a useless title with "Error!" or "Warning", those have been removed, as this is handled by the client-side widget that displays the messages.

This commit introduces a more consistent policy for logging errors and warnings:
 - All messages that do not require administrator attention should be logged at INFO level or lower. This includes all errors that are notified to the user in a friendly manner, even for access right problems or validation errors during business operations.
 - All messages that indicate a likely misconfiguration or malicious use by the users should be logged at WARNING level, as they typically require administrator attention.
 - All other unhandled internal errors cannot typically be handled by the user and should be logged at ERROR or higher level, as they require immediate administrator attention.
2015-01-16 17:15:18 +01:00
Raphael Collet 309e3def30 [FIX] api: fix api decorators to not add '_api' on original methods
This fixes an issue where the same function is used in several model classes:
once the function is wrapped for the first class, it is erroneously considered
as a wrapper for the second class, and is therefore not wrapped in other
classes.
2015-01-15 16:43:46 +01:00