Skip to content

[20.0][MIG] bus_alt_connection: Migration to 20.0 - #3807

Open
Expert-Odoo wants to merge 18 commits into
OCA:20.0from
Expert-Odoo:20.0-mig-bus_alt_connection
Open

Expert-Odoo wants to merge 18 commits into
OCA:20.0from
Expert-Odoo:20.0-mig-bus_alt_connection

Conversation

@Expert-Odoo

@Expert-Odoo Expert-Odoo commented Oct 24, 2026 •

Copy link
Copy Markdown

Migration of bus_alt_connection from 19.0 to 20.0.

The bus dispatcher was rewritten in core 20.0, so this module could not be
ported as is: everything it patched has moved or disappeared.

Adaptations to 20.0

models/bus.py — rewritten against the new dispatcher

  • ImDispatch no longer exists. The listener now lives in the new
    odoo.addons.bus.bus_dispatcher module, as BusDispatcher, a thread with a
    worker pool, and the method to override is _listener_loop, not loop.
    The module now subclasses BusDispatcher.
  • The singleton moved too: dispatch is defined in
    odoo.addons.bus.bus_dispatcher and imported by models.ir_websocket and
    websocket, so the three references are replaced, as before.
  • The loop body is mirrored from core, with one difference: core opens the
    listening cursor through odoo.sql_db.db_connect(config["db_system"]), which
    goes through the pooler, while this module opens a plain psycopg2 connection
    built from imdispatcher_db_host / imdispatcher_db_port. That difference
    is the entire point of the module, since a pooler in transaction mode never
    delivers the asynchronous notifications a LISTEN depends on. The dispatch
    flow itself (topics, states, queue, workers) is left untouched to core.
  • The connection is now closed in a finally, which the 19.0 version did not do.

Mirroring a core loop is not ideal, and I would gladly take a better
suggestion. I could not find a seam in 20.0 that lets the listening connection
be swapped without reimplementing the loop; if maintainers know one, say so and
I will rework it.

Testing

  • pre-commit run -a: green.
  • The module has no tests, and the behaviour it targets needs a pooler in front
    of PostgreSQL, which I could not reproduce. What I did verify, on a live 20.0
    instance, is that the replacement dispatcher takes over and that the bus still
    works end to end through it:
    • the server logs
      odoo.addons.bus_alt_connection.models.bus: Bus._listener_loop listen imbus on db postgres (via db:5432) instead of core's line, and
      Bus: starting 1 dispatch workers right after;
    • with a browser subscribed to a channel, bus.bus._sendone(user, …) from a
      shell is received by the client, so LISTEN → queue → worker → websocket
      all still work with the overridden loop.

Someone running PgBouncer would be welcome to confirm the pooler case.

@trobz

@Expert-Odoo Expert-Odoo mentioned this pull request Oct 24, 2026
4 of 30 tasks
@OCA-git-bot OCA-git-bot added mod:bus_alt_connection Module bus_alt_connection series:20.0 labels Oct 24, 2026
@Expert-Odoo
Expert-Odoo force-pushed the 20.0-mig-bus_alt_connection branch from 2a371f6 to b8967d0 Compare October 25, 2026 06:44
@leemannd

leemannd commented Nov 2, 2026

Copy link
Copy Markdown
Contributor

Hello, I created a PR to fix/update the documentation. Is it possible to include it? #3814

@Expert-Odoo
Expert-Odoo force-pushed the 20.0-mig-bus_alt_connection branch from b8967d0 to 417291e Compare November 2, 2026 16:07
@oca-cla-bot

oca-cla-bot Bot commented Nov 2, 2026 •

Copy link
Copy Markdown

All commit authors signed the Contributor License Agreement.

CLA signed

@Expert-Odoo

Copy link
Copy Markdown
Author

Thanks, good catch. Included in the 20.0 branch (CONFIGURE, README and index.html). The code already reads ODOO_IMDISPATCHER_DB_*, so the doc now matches.

@BhaveshHeliconia BhaveshHeliconia left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM!

Just non-blocking suggestion!

Comment thread bus_alt_connection/models/bus.py Outdated
Comment on lines +72 to +79
while conn.notifies:
for channel in orjson.loads(conn.notifies.pop().payload):
try:
channels_by_dbname[channel[0]].append(tuplify(channel))
except (IndexError, TypeError):
# Protect against malformed channels.
_logger.debug(
"Discarding malformed bus channel %s", channel

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
while conn.notifies:
for channel in orjson.loads(conn.notifies.pop().payload):
try:
channels_by_dbname[channel[0]].append(tuplify(channel))
except (IndexError, TypeError):
# Protect against malformed channels.
_logger.debug(
"Discarding malformed bus channel %s", channel
while conn.notifies:
payload = conn.notifies.pop().payload
try:
for channel in orjson.loads(payload):
channel = tuplify(channel)
hash(channel) # used as a key of _topic_by_channel
channels_by_dbname[channel[0]].append(channel)
except (ValueError, LookupError, TypeError):
_logger.warning("Bus._listener_loop ignored malformed imbus payload: %r", payload)

Matches Odoo 20 core so invalid JSON or an unhashable channel gets skipped cleanly instead of dropping and reconnecting the LISTEN connection via _run_with_retry.

@Expert-Odoo
Expert-Odoo force-pushed the 20.0-mig-bus_alt_connection branch from 1814a67 to 99d5e53 Compare December 2, 2026 14:32
@Expert-Odoo

Copy link
Copy Markdown
Author

Thanks, applied. Aligned with core 20.0: the whole payload parse is now in one try, so a malformed payload is logged and skipped instead of dropping the LISTEN connection.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

9 participants