Description:
On a database with heavy activity, it is possible for the payload
size we pass for the `NOTIFY` query on the bus to be larger than what
PostgreSQL allows by default, 8000 B. This limit is defined as:
https://github.com/postgres/postgres/blob/6686e9676c8faff4ee04c1574e117ae38f117efa/src/backend/commands/async.c#L158-L166
and it is used to compare the size of the payload before processing:
https://github.com/postgres/postgres/blob/6686e9676c8faff4ee04c1574e117ae38f117efa/src/backend/commands/async.c#L654-L657
Fix:
- Binary split the payload into multiple chunks if it's exceeding
the above-mentioned limit. The unit of splitting is a channel, so
if the content of one channel itself is larger than said limit, it
is not handled, but shouldn't occur under normal circumstances.
- Introduce also a new ENV variable `ODOO_NOTIFY_PAYLOAD_MAX_LENGTH`
to allow tweaking of the limit if they are running a handrolled
custom PostgreSQL cluster.
Reference:
opw-3650618
closesodoo/odoo#159469
X-original-commit: 61c7bba44990522d853bae25aa7899cb03c72e31
Signed-off-by: Xavier Morel (xmo) <xmo@odoo.com>
Signed-off-by: Piryns Victor (pivi) <pivi@odoo.com>
Before this commit, the `test_websocket_instances_weak_set` was
sometimes failing. Indeed, this test doesn't wait for the connection
to be fully established before making its assertions. This commit
fixes this issue.
fixes runbot-55037,55035
closesodoo/odoo#157510
X-original-commit: 15bad5ccbeced41127eeaea3e47eebbc3f55091e
Signed-off-by: Matthieu Stockbauer (tsm) <tsm@odoo.com>
When a message is posted, the server sends a `mail.record/insert`
notification to update the related channel pin state. In order to
recognize the thread, the client needs its id and its model.
Currently, only the id is passed so the thread pin state is not
updated. This PR adds the model to the notification.
closesodoo/odoo#155150
Signed-off-by: Sébastien Theys (seb) <seb@odoo.com>
*: mail.
This PR removes the live chat sidebar category. From now on, each
channel will have its own category. This is a first step towards
providing an efficient way for operators to join/leave a live chat
channel.
part of task-3640730
closesodoo/odoo#154755
Signed-off-by: Sébastien Theys (seb) <seb@odoo.com>
Since 16.3, opening the web client on the Odoo backends results in two
subscribe events being sent through the bus websocket.
Discuss listens to the thread changes to know when the subscription
should be refreshed. In order to do so, the last subscription that was
made is kept. This issue is that this subscription is empty in the
first place so the first evaluation always considers the subscription
should be made.
In order to fix this issue, this PR refine the condition to determine
if the subscription should be renewed:
- The last subscription is different from the last one
- The user joined a channel after the bus initialization
- The user left a channel after the bus initialization
In order to test those scenario in a reliable way, this PR also
backports odoo#147455
closesodoo/odoo#154170
X-original-commit: 109b45f
Signed-off-by: Sébastien Theys (seb) <seb@odoo.com>
Signed-off-by: Matthieu Stockbauer (tsm) <tsm@odoo.com>
The version of werkzeug installed can vary from one deployment
to another, as we recommend to use the operating system package,
and the version can therefore change according to the operating
system version.
e.g. the werkzeug version installed using
`apt install python3-werkzeug` varies between
Ubuntu 18.04, 20.04, 22.04, 23.10, ...
We want to keep under control the attributes
developers use on werkzeug.wrappers.Request,
to avoid compatibility issues from one
version to another.
Therefore, this revision aims
to subclass werkzeug.wrappers.Request to limit
the attributes which can be used.
task-3734305
Part-of: odoo/odoo#78857
Signed-off-by: Julien Castiaux (juc) <juc@odoo.com>
For a first iteration, Russian translations were done using DeepL using
1 large .pot file of all the standard modules to translate (e.g. no
localizations, no test modules, etc). Unfortunately for some reason
doing a msgmerge with the existing ru.po files didn't seem to work, so
old "Translators" metadata at top of files were lost (maybe they will be
re-added during next Transifex sync?)
Part-of: odoo/odoo#152285
do not compare types, for exact checks use `is` / `is not`,
for instance checks use `isinstance()`Flake8(E721)
Signed-off-by: Rémy Voet (ryv) <ryv@odoo.com>
Internal attributes of our Websocket class are
not supposed to be overridden or even used by developers
in business modules.
Ensure that by name mangling these attributes,
to make the use of them harder and make understand
those attributes are meant for the internal use
within the Websocket class only.
Part-of: odoo/odoo#75510
The kanban view used to display message history of livechats sessions is
replaced by Discuss for a smooth and consistent user experience.
Minimum viable version for Task-3497801
closesodoo/odoo#146800
Signed-off-by: Sébastien Theys (seb) <seb@odoo.com>
In [1], a context object was added to websocket requests to subscribe
to guests channels on cors live chats. However, the common mechanism
to subscribe to record channels is to pass a string channel that will
then be validated by the `_subscribe` method of `ir_websocket`. This
approach works with OdooSH out of the box while the other one does
not.
This PR removes the mechanism introduce in [1] in favor of the string
approach.
[1]: https://github.com/odoo/odoo/pull/130052closesodoo/odoo#147114
Signed-off-by: Matthieu Stockbauer (tsm) <tsm@odoo.com>
This commit fixes a non-deterministic error in the bus module. Testing
the bus service is difficult because it relies heavily on async code.
Until now, `nextTick` was used but there is no guarantee that this is
enough. This commit introduces the `waitForChannels` method that
awaits the channel subscriptions to be done before resolving.
fixes runbot-21942,54467
closesodoo/odoo#147616
X-original-commit: 429a0668a4bed52eff1c7b8cd0c5c66261678699
Signed-off-by: Matthieu Stockbauer (tsm) <tsm@odoo.com>
Several tests are non deterministic because they are using
`assert.verifySteps` at the wrong moment. Helpers such as
`afterNextRender`, `nextTick`, `Deferred` are used but those are
either not reliable or cumbersome to setup.
This PR introduces an asynchronous API on top of
`assert.step`/`assert.verifyStep`. This will wait until steps are
executed or until the timeout is reached.
fixes runbot-52660,54471,52794
closesodoo/odoo#147455
Signed-off-by: Matthieu Stockbauer (tsm) <tsm@odoo.com>
Before this PR, the "can reconnect after late close event" test
was relying on the `nextTick` helper to check which bus events
were received when the device switches from online to offline.
This test was non deterministic since a tick might not be enough
to receive the related events: the bus service communicates with
a shared worker through the MessagePort API, the worker uses a
Websocket which dispatch events upon connection/reconnection.
This commit replaces the use of the `nextTick` helper by the
dedicated `waitForBusEvent` helper which resolves once the event
is received.
fixed runbot-45695
closesodoo/odoo#147068
Signed-off-by: Matthieu Stockbauer (tsm) <tsm@odoo.com>
`psycopg2` errors sometimes happen during tests. This is caused by
race conditions between several `cr.execute()`/`cr.fetch*`.
This is even worse with websockets that are long lived connections
that sometimes open a cursor in the middle of the test.
Before websockets, longpolling was just disabled during tests. This
commits disable websockets as well in order to prevent those errors
as much as possible.
Some live chat tours were updated in [1] after the websockets intro-
duction due to some race conditions. This was reverted as the fix
relied on a hack on websockets that are now unavailable.
fixes runbot-25357,24809
[1]: https://github.com/odoo/odoo/pull/103521closesodoo/odoo#143647
X-original-commit: e3b07a301036fcce76ebbbd856b507326b88160a
Signed-off-by: Alexandre Kühn (aku) <aku@odoo.com>
Signed-off-by: Matthieu Stockbauer (tsm) <tsm@odoo.com>
The bus service communicates with the websocket worker in
order to deliver messages coming from the bus. Most of the
time, it is using a `SharedWorker` but when this kind of
worker is not available, it fallbacks on a `Worker`.
During tests, the `SharedWorker` is mocked to prevent opening
websockets on the server. However, the `Worker` is not.
Since [1], opening websockets during tests is forbidden thus,
any test relying on `Worker` and expecting a connection to be
established would fail.
This PR solves this issue by mocking the `Worker` constructor
as well.
[1]: https://github.com/odoo/odoo/pull/141519closesodoo/odoo#143988
X-original-commit: 1c67542decb1b6ad38fd15532cb6ac82417ca6dc
Signed-off-by: Alexandre Kühn (aku) <aku@odoo.com>
Signed-off-by: Matthieu Stockbauer (tsm) <tsm@odoo.com>
Odoo periodically updates the user online status. This is
done every minute and is throttled in order to ensure it won't
be triggered more than it should.
Since [1], the underscore `throttle` function has been replaced
by the `throttleForAnimation` function. This is not equivalent:
the function won't be triggered if there is no animation which
result in an outdated user status.
This issue was highlighted by the live chat: the button does
not show up when there is no available operator.
Steps to reproduce the issue:
- Log in on Odoo with live chat installed
- Go to a web page that uses the live chat widget
- Wait more that one minute and refresh the page
- The live chat button is not shown anymore: the only
operator is considered as disconnected.
This PR fixes that issue by re-introducing the underscore
throttle function: it is robust and can be needed, not all
throttles are linked to animations.
[1]: https://github.com/odoo/odoo/pull/120437.
opw-3578517
closesodoo/odoo#142160
X-original-commit: f64a7cbad3dee3ffc365b931306b1c13c8bff536
Signed-off-by: Matthieu Stockbauer (tsm) <tsm@odoo.com>
When the bus service is loaded, it connects to the websocket
worker and passes some information that are used to determine
whether the websocket connection is outdated.
Amongst them, the user id is used to detect when the user changed
and when the websocket connection should be refreshed.
This is not enough to ensure the websocket connection is still
relevant: the user id could be the same but the db could have
changed. The websocket would then be linked to the previous
database.
This commit fixes the issue by sending the db name alongside the
user id. This will ensure the connection is refreshed when it is
outdated.
Steps to reproduce the issue:
- Log in on db1 on 2 tabs
- Log out
- Log in on db2
- Try to star a message in the discuss app
- Nothing happens, the messages are sent from db2 but the socket
listens to db1
closesodoo/odoo#141263
Signed-off-by: Alexandre Kühn (aku) <aku@odoo.com>
This patch provides the possibility to implement a custom security layer on top
of Odoo's imbus notification system and ir_cron live triggering system.
The key addition is the `ODOO_NOTIFY_FUNCTION` environment variable (opt-in),
which can now define a custom postgresql function to be called instead of the
default `pg_notify` function. This allows for greater flexibility and control
over the notification and triggering mechanisms within Odoo.
closesodoo/odoo#140089
Signed-off-by: Fabien Meghazi (fme) <fme@odoo.com>
Previously proposed formating was trying to normalize extra in one part
of the path. This means that no extra needed a placeholder.
The implementation was meant to be more generic and extendible since a
part of the logic has to be in website.
A suggestion was made to make it more restricted but explicite by
keeping the url simple in web/controllers/binary.py but adding a
controller in website to add this extra part.
The base extra direction is now in the extension, as the min part.
Initial urls:
/web/assets/{unique}/[{website_id}/][rtl/]{bundle_name}[.min].{extension}
New urls:
/web/assets/[{website_id}]/{unique}/{bundle_name}[.rtl][.min].{extension}
Managed by two routes:
/web/assets/<string:unique>/<string:filename>
/web/assets/<int:website_id>/<string:unique>/<string:filename>
Where filename is in the format {bundle_name}[.rtl][.min].{extension}
Multiple possibilities where proposed
- /web/assets/website/<int:website_id>/<string:unique>/<string:filename>
More explicit but prefixing by /website was considered
- /website/assets/<int:website_id>/<string:unique>/<string:filename>
This one is a litle painfull to match similar attachement, where
website is ignored.
- /website/<int:website_id>/assets/<string:unique>/<string:filename>
Almost accepted but subjective, and anyway two previous solution breaks
the cdn mecanism and would need a migration
- /web/assets/<int:website_id>/<string:unique>/<string:filename>
Almost accepted but subjective, and anyway two previous solution breaks
the cdn mecanism and would need a migration
This last solution was not ideal to match without unique
/web/assets/%/<string:filename> can match both
/web/assets/123456/<string:filename>
and
/web/assets/1/123456/<string:filename>
Anyway, matching without unique shouldn't be supported for al (even if
it is kind of supported with any right now) but it will work by changing
unique wildcard to a more specific one (_ * 7)
closesodoo/odoo#131353
Related: odoo/enterprise#47313
Related: odoo/design-themes#730
Signed-off-by: Xavier Dollé (xdo) <xdo@odoo.com>
The generation inside the rendering has some drawbacks:
- `commit_assetsbundle` is needed for reports rendering because the
template rendering may generate some assets that will be accessed by
another transaction before the transaction is committed. But this
solution is not ideal since the transaction is committed in the middle
of the request
- when the first rendered page is a 404, the assets are not committed
and the page is broken.
- when starting, deleting an attachment can create a concurrent update
error and the request is retried. This will occur once per attachment
and for all worker trying to access the same resource. The whole
transaction is rollbacked, even the previously created assets bundle.
- The cold page load is a slower since there is more work to do.
- Implementing a readonly request is difficult because it could be
transformed to read write and re-executed if the assets bundle does not
exist.
Generating assets when needed solves those issues. The concurrency
when deleting an assets could still occur but only once per bundle, and
in a smaller transaction. This could be solved with a lock now that we
have more control on the transaction. The commit_assetsbundle can be
removed and 404 page should have a correct layout. The cold page load
could be a little faster because the assets bundle can be generated in
parallel requests instead of sequentially when rendering the page.
Part-of: odoo/odoo#131353
This commit removes the promise extension which added the function
`guardedCatch`. It was used to filter server and connection errors from
javascript errors. Instead of using guardedCatch, we should use catch
and check if the reason is a server or connection error if needed and
re-throw the error if it's not handled.
closesodoo/odoo#137702
Task: 3439226
Related: odoo/enterprise#48451
Signed-off-by: Aaron Bohy (aab) <aab@odoo.com>
As a step to simplify model insert from python. All data are
formatted in a way to make data insert trivial in JS models.
closesodoo/odoo#138760
Signed-off-by: Sébastien Theys (seb) <seb@odoo.com>
`_authenticate` is updating the `env`, but it updated the `env` of
`ir_websocket` instead of `self`. There was then a mismatch between
the `update_context` and the current user.
This was highlighted in another PR that removed sudo from these methods
with the hope on relying on ACL, which depends on current user and other
context values at the same time.
closesodoo/odoo#139436
Signed-off-by: Matthieu Stockbauer (tsm) <tsm@odoo.com>
[1] tried to remove nondeterminism from bus tests. However, several
issues remain:
- the asset watchdog bundle is added to the registry during bus tests.
Websocket tests wait for the `connect` event after starting the environment.
This `connect` event can be triggered sooner than expected since the asset
watchdog services starts the bus.
- a the random delay is added to the reconnection attempts.
- `nextTick` is kept when waiting for a client to leave the worker.
This commit fixes those issues.
[1]: https://github.com/odoo/odoo/pull/138221closesodoo/odoo#138639
Signed-off-by: Alexandre Kühn (aku) <aku@odoo.com>
Before this commit, websocket tests were sometimes failing with the
`no result to fetch` error. This is due to a race between the
`subscribe` event being received which itself leads to dispatching bus
notifications interferring with the rest of the test (the connection
is shared).
In order to solve this issue, the `WebsocketCase` now exposes a
`subscribe` method that waits for this dispatching to be done in order
to ensure it will not interfere with the rest of the test.
Some tests were also failing because the subscription was done with 0
as the last notification id. This is an issue since this could lead to
notifications being sent while they are not expected.
In order to solve this issue, `last_notification_id` is now correctly
passed when subscribing to channel notifications.
fixes runbot-24226
closesodoo/odoo#138649
X-original-commit: 3256885fd08d33a67d7165fa33d373fd039ef7af
Signed-off-by: Alexandre Kühn (aku) <aku@odoo.com>
Signed-off-by: Matthieu Stockbauer (tsm) <tsm@odoo.com>
This commit makes bus tests more robust by implementing
functions that wait for some events instead of relying
on `nextTick` that might or not be sufficient.
fixes runbot-23097
closesodoo/odoo#138221
Signed-off-by: Matthieu Stockbauer (tsm) <tsm@odoo.com>
This commit cleans the bus tests by:
- flattening the tests structure by putting tests outside
of the `QUnit.module` function.
- removing unnecessary `assert.expect` calls.
- adding an helper to add common bus service to the registry
Part-of: odoo/odoo#138221
Before this commit, diagnosing websocket handshake error was
cumbersome since the only information available was the return
code of the initial HTTP request (400).
The HTTP stack does not log `werkzeug.exceptions.HTTPException`
and derivated classes since they are valid responses. This commit
adds a log in order to provide more insight about what went wrong.
closesodoo/odoo#138083
X-original-commit: 50af40302c2849b99e8e501bc170cf887ca8e6fa
Signed-off-by: Julien Castiaux (juc) <juc@odoo.com>
Signed-off-by: Matthieu Stockbauer (tsm) <tsm@odoo.com>
Before this commit, owl was in the linter's accepted global variables.
This allowed direct access to owl global object.
For instance, to use xml from owl, you could do :
`const { xml } = owl;`
or you could use it directly:
`owl.xml`
Now, owl is not accepted on linter's global variables anymore, so to
import xml, now you need to use a proper import:
`import { xml } from "@odoo/owl";`
task-id 3498859
closesodoo/odoo#137517
Related: odoo/enterprise#48364
Related: odoo/design-themes#709
Signed-off-by: Samuel Degueldre (sad) <sad@odoo.com>
This commit removes the legacy service mappers which are useless now.
closesodoo/odoo#136807
Task: 3439226
Related: odoo/enterprise#48015
Signed-off-by: Mathieu Duckerts-Antoine (dam) <dam@odoo.com>
- `Response.charset` is deprecated since 2.3, `Response.set_cookie`
accesses the currently-extent internal `_charset` directly until
this too gets removed in Werkzeug 3.0. Add a `_charset` to
`FutureResponse` so this does not crash.
- Bytes response headers are deprecated since 2.3, and will get
removed in 3.0, passing bytes in websocket is completely unnecessary
happenstance which is trivially fixed.
closesodoo/odoo#137145
X-original-commit: 66e3040d4ad9e03aabefebd4799f699ad30fca45
Signed-off-by: Julien Castiaux (juc) <juc@odoo.com>
Signed-off-by: Xavier Morel (xmo) <xmo@odoo.com>
* = bus, calendar, im_livechat, hr, project_todo, sms, snailmail,
test_mail, web, website_livechat
The current implementation often led to tests relying on DOM structure
to properly target the correct element with the text.
It is now easier to simply check if a parent contains some text.
closesodoo/odoo#136295
Related: odoo/enterprise#47770
Signed-off-by: Alexandre Kühn (aku) <aku@odoo.com>
* = account, base_iban, bus, calendar, crm_livechat, hr, hr_holidays,
im_livechat, mrp, project, sms, snailmail, test_mail,
test_mail_full, web, website_livechat, website_slides
Add support in `contains` for most operations that we use in tests.
Remove return value from `contains`.
Move into `web` module.
Remove import/export chains, directly import from correct module.
closesodoo/odoo#134652
Related: odoo/enterprise#47064
Signed-off-by: Sébastien Theys (seb) <seb@odoo.com>