<feed xmlns='http://www.w3.org/2005/Atom'>
<title>Odoo/odoo/sql_db.py, branch 14.0</title>
<subtitle>The current checkout of upstream Odoo</subtitle>
<link rel='alternate' type='text/html' href='http://erp.ceuconsult.com:9000/Odoo/'/>
<entry>
<title>[FIX] core: Ensure that rollback hooks are called when the cursor is closed</title>
<updated>2020-10-20T08:43:02+00:00</updated>
<author>
<name>Laurent Mignon (ACSONE)</name>
<email>laurent.mignon@acsone.eu</email>
</author>
<published>2020-07-10T10:43:38+00:00</published>
<link rel='alternate' type='text/html' href='http://erp.ceuconsult.com:9000/Odoo/commit/?id=09bf7bd760136ddf55fc7e695a4b6c08d5fc4fed'/>
<id>09bf7bd760136ddf55fc7e695a4b6c08d5fc4fed</id>
<content type='text'>
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#60334

X-original-commit: dce9a05f3a5d37fab711c8ca3c5444941f98e814
Signed-off-by: Raphael Collet (rco) &lt;rco@openerp.com&gt;
Co-authored-by: Raphael Collet &lt;rco@odoo.com&gt;
</content>
<content type='xhtml'>
<div xmlns='http://www.w3.org/1999/xhtml'>
<pre>
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#60334

X-original-commit: dce9a05f3a5d37fab711c8ca3c5444941f98e814
Signed-off-by: Raphael Collet (rco) &lt;rco@openerp.com&gt;
Co-authored-by: Raphael Collet &lt;rco@odoo.com&gt;
</pre>
</div>
</content>
</entry>
<entry>
<title>[FIX] core: preferably flush() with an env with a real uid</title>
<updated>2020-10-09T13:39:02+00:00</updated>
<author>
<name>Raphael Collet</name>
<email>rco@odoo.com</email>
</author>
<published>2020-10-06T09:12:05+00:00</published>
<link rel='alternate' type='text/html' href='http://erp.ceuconsult.com:9000/Odoo/commit/?id=507295ca80e8eac9c75714f41b599d9e2e8a2549'/>
<id>507295ca80e8eac9c75714f41b599d9e2e8a2549</id>
<content type='text'>
This fixes a crash in some controllers with `auth='None'` where some
updates are flushed with an environment where `uid=None`.  When there is
an environment with a real uid, preferably use it.

closes odoo/odoo#59650

X-original-commit: 2795c86df54389b858a454cbc1782b1f34f3ba4f
Signed-off-by: Raphael Collet (rco) &lt;rco@openerp.com&gt;
</content>
<content type='xhtml'>
<div xmlns='http://www.w3.org/1999/xhtml'>
<pre>
This fixes a crash in some controllers with `auth='None'` where some
updates are flushed with an environment where `uid=None`.  When there is
an environment with a real uid, preferably use it.

closes odoo/odoo#59650

X-original-commit: 2795c86df54389b858a454cbc1782b1f34f3ba4f
Signed-off-by: Raphael Collet (rco) &lt;rco@openerp.com&gt;
</pre>
</div>
</content>
</entry>
<entry>
<title>[IMP] core: deprecate method cr.after()</title>
<updated>2020-09-03T09:17:26+00:00</updated>
<author>
<name>Raphael Collet</name>
<email>rco@odoo.com</email>
</author>
<published>2020-09-03T09:17:26+00:00</published>
<link rel='alternate' type='text/html' href='http://erp.ceuconsult.com:9000/Odoo/commit/?id=e9e37091a65d5ae2caa9eb6728abaffb7c9555a8'/>
<id>e9e37091a65d5ae2caa9eb6728abaffb7c9555a8</id>
<content type='text'>
Use the more convenient `cr.postcommit.add()` instead.

closes odoo/odoo#56990

Related: odoo/enterprise#12914
Signed-off-by: Raphael Collet (rco) &lt;rco@openerp.com&gt;
</content>
<content type='xhtml'>
<div xmlns='http://www.w3.org/1999/xhtml'>
<pre>
Use the more convenient `cr.postcommit.add()` instead.

closes odoo/odoo#56990

Related: odoo/enterprise#12914
Signed-off-by: Raphael Collet (rco) &lt;rco@openerp.com&gt;
</pre>
</div>
</content>
</entry>
<entry>
<title>[FIX] core: cursor hooks API and implementation</title>
<updated>2020-09-03T09:05:21+00:00</updated>
<author>
<name>Raphael Collet</name>
<email>rco@odoo.com</email>
</author>
<published>2020-08-28T14:11:21+00:00</published>
<link rel='alternate' type='text/html' href='http://erp.ceuconsult.com:9000/Odoo/commit/?id=d4b2e9224839aed8fc160ebe5a89e0f7d4c6a5bb'/>
<id>d4b2e9224839aed8fc160ebe5a89e0f7d4c6a5bb</id>
<content type='text'>
Python 3.8 changed the equality rules for bound methods to be based on
the *identity* of the receiver (`__self__`) rather than its *equality*.
This means that in 3.7, methods from different instances will compare
(and hash) equal, thereby landing in the same map "slot", but that isn't
the case in 3.8.

While it's usually not relevant, it's an issue for `GroupCalls` which is
indexed by a function: in 3.7, that being a method from recordsets
comparing equal will deduplicate them, but not anymore in 3.8, leading
to duplicated callbacks (exactly the thing GroupCalls aims to avoid).

Also, the API of `GroupCalls` turned out to be unusual and weird.  The
bug above is fixed by using a plain list for callbacks, thereby avoiding
comparisons between registered functions.  The API is now:

    callbacks.add(func)     # add func to callbacks
    callbacks.run()         # run all callbacks in addition order
    callbacks.clear()       # remove all callbacks

In order to handle aggregated data, the `callbacks` object provides a
dictionary `callbacks.data` that any callback function can freely use.
For the sake of consistency, the `callbacks.data` dict is automatically
cleared upon execution of callbacks.

Discovered by @william-andre

Related to odoo#56583

References:

* https://bugs.python.org/issue1617161
* python/cpython#7848
* https://docs.python.org/3/whatsnew/changelog.html#python-3-8-0-alpha-1
  (no direct link because individual entries are not linkable, look for
  bpo-1617161)

X-original-commit: a986f4929bab95759086cc77ca5e60795f82e91a</content>
<content type='xhtml'>
<div xmlns='http://www.w3.org/1999/xhtml'>
<pre>
Python 3.8 changed the equality rules for bound methods to be based on
the *identity* of the receiver (`__self__`) rather than its *equality*.
This means that in 3.7, methods from different instances will compare
(and hash) equal, thereby landing in the same map "slot", but that isn't
the case in 3.8.

While it's usually not relevant, it's an issue for `GroupCalls` which is
indexed by a function: in 3.7, that being a method from recordsets
comparing equal will deduplicate them, but not anymore in 3.8, leading
to duplicated callbacks (exactly the thing GroupCalls aims to avoid).

Also, the API of `GroupCalls` turned out to be unusual and weird.  The
bug above is fixed by using a plain list for callbacks, thereby avoiding
comparisons between registered functions.  The API is now:

    callbacks.add(func)     # add func to callbacks
    callbacks.run()         # run all callbacks in addition order
    callbacks.clear()       # remove all callbacks

In order to handle aggregated data, the `callbacks` object provides a
dictionary `callbacks.data` that any callback function can freely use.
For the sake of consistency, the `callbacks.data` dict is automatically
cleared upon execution of callbacks.

Discovered by @william-andre

Related to odoo#56583

References:

* https://bugs.python.org/issue1617161
* python/cpython#7848
* https://docs.python.org/3/whatsnew/changelog.html#python-3-8-0-alpha-1
  (no direct link because individual entries are not linkable, look for
  bpo-1617161)

X-original-commit: a986f4929bab95759086cc77ca5e60795f82e91a</pre>
</div>
</content>
</entry>
<entry>
<title>[FIX] core: flushing an environment should not leave things to compute</title>
<updated>2020-06-11T14:40:33+00:00</updated>
<author>
<name>Raphael Collet</name>
<email>rco@odoo.com</email>
</author>
<published>2020-05-06T12:46:04+00:00</published>
<link rel='alternate' type='text/html' href='http://erp.ceuconsult.com:9000/Odoo/commit/?id=4f9efd2eb1481adf8234af6f462e5a7900c089c0'/>
<id>4f9efd2eb1481adf8234af6f462e5a7900c089c0</id>
<content type='text'>
Upon cursor `commit()`, the pending computations are performed with
method `flush()`.  However the latter method leaves fields to compute on
new records.  As the `commit` ends the current transaction, we can clear
those pending computations.

X-original-commit: d27e98d9048d0cb1250522205286ebc7b7d5ea39</content>
<content type='xhtml'>
<div xmlns='http://www.w3.org/1999/xhtml'>
<pre>
Upon cursor `commit()`, the pending computations are performed with
method `flush()`.  However the latter method leaves fields to compute on
new records.  As the `commit` ends the current transaction, we can clear
those pending computations.

X-original-commit: d27e98d9048d0cb1250522205286ebc7b7d5ea39</pre>
</div>
</content>
</entry>
<entry>
<title>[FIX] sql_db: flush when no `uid` in environment</title>
<updated>2020-04-01T00:30:30+00:00</updated>
<author>
<name>Toufik Ben Jaa</name>
<email>tbe@odoo.com</email>
</author>
<published>2020-03-31T16:05:32+00:00</published>
<link rel='alternate' type='text/html' href='http://erp.ceuconsult.com:9000/Odoo/commit/?id=707522cb010ac4efc04a5eeeb04d02b04d721521'/>
<id>707522cb010ac4efc04a5eeeb04d02b04d721521</id>
<content type='text'>
- A bug has been introduced by the PR https://github.com/odoo/odoo/pull/46719
  This issue prevented flushes to database when no `uid` is set in the
  current environment.
  This happens when database changes are made in `auth="none"` routes.
  In a MonoDB setup this was working because Odoo consider `None`, `False` as
  `null` and was always bound to a database.

  Nothing prevents to write `null` in the columns `create_uid` and
  `write_uid` in database.
  The PR that introduced the bug wanted to block the cases where
  `uid` is an instance of the class `RequestUID` to avoid `Cannot adapt
  type` errors.
  So testing that `uid` is an integer isn't enough.

  Two fixes were possible here, either check if `uid` is an instance
  of the class `RequestUID` or if it is either an integer, `False` or `None`.

  To avoid noise and imports from `odoo`, we test that `uid` is an instance
  of `None`.
  The case where it is `False` is already tested in the python code:

  ```python
	isinstance(env.uid, int)
  ```

(manual) forward-port of odoo/odoo#48685

closes odoo/odoo#48693

Signed-off-by: Toufik Benjaa (tbe) &lt;tbe@odoo.com&gt;
Signed-off-by: Olivier Dony (odo) &lt;odo@openerp.com&gt;
</content>
<content type='xhtml'>
<div xmlns='http://www.w3.org/1999/xhtml'>
<pre>
- A bug has been introduced by the PR https://github.com/odoo/odoo/pull/46719
  This issue prevented flushes to database when no `uid` is set in the
  current environment.
  This happens when database changes are made in `auth="none"` routes.
  In a MonoDB setup this was working because Odoo consider `None`, `False` as
  `null` and was always bound to a database.

  Nothing prevents to write `null` in the columns `create_uid` and
  `write_uid` in database.
  The PR that introduced the bug wanted to block the cases where
  `uid` is an instance of the class `RequestUID` to avoid `Cannot adapt
  type` errors.
  So testing that `uid` is an integer isn't enough.

  Two fixes were possible here, either check if `uid` is an instance
  of the class `RequestUID` or if it is either an integer, `False` or `None`.

  To avoid noise and imports from `odoo`, we test that `uid` is an instance
  of `None`.
  The case where it is `False` is already tested in the python code:

  ```python
	isinstance(env.uid, int)
  ```

(manual) forward-port of odoo/odoo#48685

closes odoo/odoo#48693

Signed-off-by: Toufik Benjaa (tbe) &lt;tbe@odoo.com&gt;
Signed-off-by: Olivier Dony (odo) &lt;odo@openerp.com&gt;
</pre>
</div>
</content>
</entry>
<entry>
<title>[FIX] core: do not flush() with an environment using RequestUID</title>
<updated>2020-03-27T11:48:43+00:00</updated>
<author>
<name>Raphael Collet</name>
<email>rco@odoo.com</email>
</author>
<published>2020-03-12T09:42:15+00:00</published>
<link rel='alternate' type='text/html' href='http://erp.ceuconsult.com:9000/Odoo/commit/?id=8e44b395707ec54a057388516f9a7fdbc54c0dfb'/>
<id>8e44b395707ec54a057388516f9a7fdbc54c0dfb</id>
<content type='text'>
When routing an HTTP request, the dispatcher uses an environment with a
placeholder for the user (the object `RequestUID`).  This environment is
not supposed to be used after routing has been done.  However, the
flushing function takes any environment with a given cursor, and it
crashes when this environment is chosen (`psycopg2` cannot adapt the
type `RequestUID` for `write_uid`), and simply does not make sense.

closes odoo/odoo#48495

X-original-commit: da61a64bf6731a08557d23680eabf4d910035ebd
Signed-off-by: Raphael Collet (rco) &lt;rco@openerp.com&gt;
</content>
<content type='xhtml'>
<div xmlns='http://www.w3.org/1999/xhtml'>
<pre>
When routing an HTTP request, the dispatcher uses an environment with a
placeholder for the user (the object `RequestUID`).  This environment is
not supposed to be used after routing has been done.  However, the
flushing function takes any environment with a given cursor, and it
crashes when this environment is chosen (`psycopg2` cannot adapt the
type `RequestUID` for `write_uid`), and simply does not make sense.

closes odoo/odoo#48495

X-original-commit: da61a64bf6731a08557d23680eabf4d910035ebd
Signed-off-by: Raphael Collet (rco) &lt;rco@openerp.com&gt;
</pre>
</div>
</content>
</entry>
<entry>
<title>[FIX] sql_db: remove unused __closer</title>
<updated>2020-03-13T15:24:54+00:00</updated>
<author>
<name>Julien Castiaux</name>
<email>juc@odoo.com</email>
</author>
<published>2020-02-19T13:06:12+00:00</published>
<link rel='alternate' type='text/html' href='http://erp.ceuconsult.com:9000/Odoo/commit/?id=92b17aadd28d0a80f9278d55b03ea6e60feb6040'/>
<id>92b17aadd28d0a80f9278d55b03ea6e60feb6040</id>
<content type='text'>
The `__closer` attribute is filled with the origin of a call to
`cr.close()`. That information is reused in the `check` decotator that
ensure the user is not using a closed cursor. In case he is using a
closed cursor, an error is raised with that optional origin in case of
`--log-sql`.

The attribute is a dundler so it is only accessible within its class, as
the decorator has been moved outside of the class by 058cf208a8e7 it is
not directly accessible thus `__getattr__` is called as a fallback. The
`__getattr__` itself is protected by the `check` decorator thus they
call each other in a infinite recursion.

As the related dundler is no more used internally, it has been decided
to remove it entirely.

closes odoo/odoo#47616

Task: 2199895
X-original-commit: 3ebf7cb9cca37b05f44aaffc0b1f289cc65f300f
Signed-off-by: Julien Castiaux &lt;Julien00859@users.noreply.github.com&gt;
</content>
<content type='xhtml'>
<div xmlns='http://www.w3.org/1999/xhtml'>
<pre>
The `__closer` attribute is filled with the origin of a call to
`cr.close()`. That information is reused in the `check` decotator that
ensure the user is not using a closed cursor. In case he is using a
closed cursor, an error is raised with that optional origin in case of
`--log-sql`.

The attribute is a dundler so it is only accessible within its class, as
the decorator has been moved outside of the class by 058cf208a8e7 it is
not directly accessible thus `__getattr__` is called as a fallback. The
`__getattr__` itself is protected by the `check` decorator thus they
call each other in a infinite recursion.

As the related dundler is no more used internally, it has been decided
to remove it entirely.

closes odoo/odoo#47616

Task: 2199895
X-original-commit: 3ebf7cb9cca37b05f44aaffc0b1f289cc65f300f
Signed-off-by: Julien Castiaux &lt;Julien00859@users.noreply.github.com&gt;
</pre>
</div>
</content>
</entry>
<entry>
<title>[ADD] sql_db: pre/post-commit/rollback hooks</title>
<updated>2020-02-05T13:50:23+00:00</updated>
<author>
<name>Raphael Collet</name>
<email>rco@odoo.com</email>
</author>
<published>2019-11-26T16:04:02+00:00</published>
<link rel='alternate' type='text/html' href='http://erp.ceuconsult.com:9000/Odoo/commit/?id=058cf208a8e7d43ebfc2e761ec1cbfc6e7a56351'/>
<id>058cf208a8e7d43ebfc2e761ec1cbfc6e7a56351</id>
<content type='text'>
</content>
<content type='xhtml'>
<div xmlns='http://www.w3.org/1999/xhtml'>
<pre>
</pre>
</div>
</content>
</entry>
<entry>
<title>[FIX] Log failed queries decoded</title>
<updated>2019-10-08T14:12:23+00:00</updated>
<author>
<name>Jairo Llopis</name>
<email>yajo.sk8@gmail.com</email>
</author>
<published>2019-10-07T11:44:00+00:00</published>
<link rel='alternate' type='text/html' href='http://erp.ceuconsult.com:9000/Odoo/commit/?id=8ad360ccd3673a77c81e39b08236928fc2fe6c9d'/>
<id>8ad360ccd3673a77c81e39b08236928fc2fe6c9d</id>
<content type='text'>
Starting with Python 3, queries sent by psyocopg2 are stored as `bytes()` objects.

Logging those raw makes them appear unformatted, harder to read than in v10 or lower Odoo versions (i.e. `\n` instead of a raw newline character).

Decoding the query into unicode makes it easier to read in the logs.

closes odoo/odoo#38074

X-original-commit: 329accde2ed6d4dbfdde6d3d99d71e21d15396b7
Signed-off-by: Christophe Simonis &lt;chs@odoo.com&gt;
</content>
<content type='xhtml'>
<div xmlns='http://www.w3.org/1999/xhtml'>
<pre>
Starting with Python 3, queries sent by psyocopg2 are stored as `bytes()` objects.

Logging those raw makes them appear unformatted, harder to read than in v10 or lower Odoo versions (i.e. `\n` instead of a raw newline character).

Decoding the query into unicode makes it easier to read in the logs.

closes odoo/odoo#38074

X-original-commit: 329accde2ed6d4dbfdde6d3d99d71e21d15396b7
Signed-off-by: Christophe Simonis &lt;chs@odoo.com&gt;
</pre>
</div>
</content>
</entry>
</feed>
