[SOLVED]? Insert or update on table "storageadmin_networkdevice" violates foreign key constraint "storageadmin_network_connection_id_6a520cbf_fk_storagead"DETAIL: Key (connection_id)=(33) is not present in table "storageadmin_networkconnection"

Brief description of the problem

I was just browsing the Web UI when, after clicking in System → Network, I just saw the error in the attached screenshot. As a subscriber to Stable updates I just followed the on-screen directions and hence here I am.

Detailed step by step instructions to reproduce the problem

I went to 192.168.1.100 on my browser (Rockstor NAS local address), then System → Network

Web-UI screenshot

Error Traceback provided on the Web-UI

Traceback (most recent call last):
File “/opt/rockstor/.venv/lib/python3.11/site-packages/django/db/backends/base/base.py”, line 312, in _commit
return self.connection.commit()
^^^^^^^^^^^^^^^^^^^^^^^^
File “/opt/rockstor/.venv/lib/python3.11/site-packages/psycopg/connection.py”, line 262, in commit
self.wait(self._commit_gen())
File “/opt/rockstor/.venv/lib/python3.11/site-packages/psycopg/connection.py”, line 414, in wait
return waiting.wait(gen, self.pgconn.socket, interval=interval)
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
File “/opt/rockstor/.venv/lib/python3.11/site-packages/psycopg/waiting.py”, line 354, in wait_poll
s = gen.send(ready)
^^^^^^^^^^^^^^^
File “/opt/rockstor/.venv/lib/python3.11/site-packages/psycopg/_connection_base.py”, line 580, in _commit_gen
yield from self._exec_command(b"COMMIT")
File “/opt/rockstor/.venv/lib/python3.11/site-packages/psycopg/_connection_base.py”, line 478, in _exec_command
raise e.error_from_result(result, encoding=self.pgconn._encoding)
psycopg.errors.ForeignKeyViolation: insert or update on table “storageadmin_networkdevice” violates foreign key constraint “storageadmin_network_connection_id_6a520cbf_fk_storagead”
DETAIL: Key (connection_id)=(33) is not present in table “storageadmin_networkconnection”.
The above exception was the direct cause of the following exception:
Traceback (most recent call last):
File “/opt/rockstor/src/rockstor/rest_framework_custom/generic_view.py”, line 40, in _handle_exception
yield
File “/opt/rockstor/src/rockstor/storageadmin/views/network.py”, line 235, in get_queryset
self._refresh_devices()
File “/usr/lib64/python3.11/contextlib.py”, line 80, in inner
with self._recreate_cm():
File “/opt/rockstor/.venv/lib/python3.11/site-packages/django/db/transaction.py”, line 263, in exit
connection.commit()
File “/opt/rockstor/.venv/lib/python3.11/site-packages/django/utils/asyncio.py”, line 26, in inner
return func(*args, **kwargs)
^^^^^^^^^^^^^^^^^^^^^
File “/opt/rockstor/.venv/lib/python3.11/site-packages/django/db/backends/base/base.py”, line 336, in commit
self._commit()
File “/opt/rockstor/.venv/lib/python3.11/site-packages/django/db/backends/base/base.py”, line 311, in _commit
with debug_transaction(self, “COMMIT”), self.wrap_database_errors:
File “/opt/rockstor/.venv/lib/python3.11/site-packages/django/db/utils.py”, line 91, in exit
raise dj_exc_value.with_traceback(traceback) from exc_value
File “/opt/rockstor/.venv/lib/python3.11/site-packages/django/db/backends/base/base.py”, line 312, in _commit
return self.connection.commit()
^^^^^^^^^^^^^^^^^^^^^^^^
File “/opt/rockstor/.venv/lib/python3.11/site-packages/psycopg/connection.py”, line 262, in commit
self.wait(self._commit_gen())
File “/opt/rockstor/.venv/lib/python3.11/site-packages/psycopg/connection.py”, line 414, in wait
return waiting.wait(gen, self.pgconn.socket, interval=interval)
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
File “/opt/rockstor/.venv/lib/python3.11/site-packages/psycopg/waiting.py”, line 354, in wait_poll
s = gen.send(ready)
^^^^^^^^^^^^^^^
File “/opt/rockstor/.venv/lib/python3.11/site-packages/psycopg/_connection_base.py”, line 580, in _commit_gen
yield from self._exec_command(b"COMMIT")
File “/opt/rockstor/.venv/lib/python3.11/site-packages/psycopg/_connection_base.py”, line 478, in _exec_command
raise e.error_from_result(result, encoding=self.pgconn._encoding)
django.db.utils.IntegrityError: insert or update on table “storageadmin_networkdevice” violates foreign key constraint “storageadmin_network_connection_id_6a520cbf_fk_storagead”
DETAIL: Key (connection_id)=(33) is not present in table “storageadmin_networkconnection”.

Just in case, I must say I have been updating the rockstor packages through the internal console by issuing “zypper refresh” followed by “zypper up” over the past year.

Also, my Immich server is working OK and I can access my pictures from outside when not at home.

On a side note, my internet provider upgraded my router to a new brand and model (TP-Link BE7200 Dual-Band Wi-Fi 7 XGS-PON) this week and, as far as I know, ports 80 and 443 are reserved by default by it and I cannot assign them to local boxes. No idea if this info is relevant or not.

[SOLVED]??? After closing the browser tab and re-opening the Web-UI, I played around clicking on other System options first and then, when clicking on Network, the error is not appearing any more. What has happened?

I am not entirely sure, why this condition would occur. However, we also have encountered other caching/stale value scenarios in the UI (which is now pretty old both with the front-end components and maintenance), so the only thing I can imagine here is that it looked at some cached value when comparing connections in the database to what’s physically there and active.
Closing the UI, and starting a new instance of that in your browser might then have cleaned up that perceived inconsistency, and the error doesn’t occur anymore.
I have seen that at some point in the past, when configuring network bridges and assigning them to Rock-ons I was experimenting with. I never traced back to the exact issue there, but then assumed the root cause was the front-end behavior and not a real issue/inconsistency in the database. One could try to determine whether a more graceful exit can be achieved in case of failure, but I suspect that will likely not happen before the planned (pending dev capacity) UI overhaul can be started and completed.
I don’t think your command line updates of packages would have caused this. Of course, now 15.6 has been EOL for some time, so the question is how many updates you’re still getting for all relevant components affected by zypper. I would also recommend to use zypper up --no-recommends to avoid unnecessary packages to be installed.
And the upgraded router for the most part would only have an impact on your assigned IP address, if you have multiple ethernet ports on your Rockstor box, did you plug into a different port? Or just switched out on the router side from old to new?