InternalError: cannot execute UPDATE with read-only DB replica #11936

Closed
opened 2025-12-29 21:51:43 +01:00 by adam · 1 comment
Owner

Originally created by @jnovinger on GitHub (Dec 18, 2025).

Originally assigned to: @jeremystretch on GitHub.

NetBox Edition

NetBox Community

NetBox Version

v4.4.8

Python Version

3.12

Steps to Reproduce

  1. Set PostgreSQL database to read-only (to act as RO replica):ALTER DATABASE netbox SET default_transaction_read_only = on;
  2. Restart NetBox (to pick up new connection settings)
  3. Make any HTTP request: http://localhost:8000/

Affected Versions: v4.4.3+ (introduced in commit 7719b9869, PR #20219, fixing #19825)

Cleanup: ALTER DATABASE netbox SET default_transaction_read_only = off;

Expected Behavior

Request succeeds, no database write errors

Observed Behavior

Request fails with InternalError: cannot execute UPDATE in a read-only transaction:

  File "netbox/middleware.py", line 221, in __call__
    if get_config().MAINTENANCE_MODE:
  File "netbox/config/__init__.py", line 28, in get_config
    _thread_locals.config = Config()
  File "netbox/config/__init__.py", line 96, in _populate_from_db
    revision.activate()
  File "core/models/config.py", line 74, in activate
    ConfigRevision.objects.all().update(active=False)
Originally created by @jnovinger on GitHub (Dec 18, 2025). Originally assigned to: @jeremystretch on GitHub. ### NetBox Edition NetBox Community ### NetBox Version v4.4.8 ### Python Version 3.12 ### Steps to Reproduce 1. Set PostgreSQL database to read-only (to act as RO replica):`ALTER DATABASE netbox SET default_transaction_read_only = on;` 2. Restart NetBox (to pick up new connection settings) 3. Make any HTTP request: http://localhost:8000/ Affected Versions: v4.4.3+ (introduced in commit 7719b9869, PR #20219, fixing #19825) Cleanup: `ALTER DATABASE netbox SET default_transaction_read_only = off;` ### Expected Behavior Request succeeds, no database write errors ### Observed Behavior Request fails with `InternalError: cannot execute UPDATE in a read-only transaction`: ``` File "netbox/middleware.py", line 221, in __call__ if get_config().MAINTENANCE_MODE: File "netbox/config/__init__.py", line 28, in get_config _thread_locals.config = Config() File "netbox/config/__init__.py", line 96, in _populate_from_db revision.activate() File "core/models/config.py", line 74, in activate ConfigRevision.objects.all().update(active=False) ```
adam added the type: bugstatus: acceptednetboxseverity: medium labels 2025-12-29 21:51:43 +01:00
adam closed this issue 2025-12-29 21:51:43 +01:00
Author
Owner

@jeremystretch commented on GitHub (Dec 22, 2025):

Note: There must be an active ConfigRevision in the database to reproduce this.

@jeremystretch commented on GitHub (Dec 22, 2025): Note: There must be an active ConfigRevision in the database to reproduce this.
Sign in to join this conversation.
1 Participants
Notifications
Due Date
No due date set.
Dependencies

No dependencies set.

Reference: starred/netbox#11936