Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

UPDATE statement on table 'vehicles' expected to update 1 row(s); 2 were matched. #683

Open
scantineau opened this issue Oct 26, 2024 · 2 comments

Comments

@scantineau
Copy link

FYI I got this error and experienced strange behaviours :

  • HAP not working anymore
  • data not updated or only when container restarted
  • no more error logs even if the problem is still there
iot_vwsfriendbackend.1.r9i5zbdfvrx4@srvnuc1    | Traceback (most recent call last):
iot_vwsfriendbackend.1.r9i5zbdfvrx4@srvnuc1    |   File "/opt/venv/bin/vwsfriend", line 8, in <module>
iot_vwsfriendbackend.1.r9i5zbdfvrx4@srvnuc1    |     sys.exit(main())
iot_vwsfriendbackend.1.r9i5zbdfvrx4@srvnuc1    |              ^^^^^^
iot_vwsfriendbackend.1.r9i5zbdfvrx4@srvnuc1    |   File "/opt/venv/lib/python3.12/site-packages/vwsfriend/vwsfriend_base.py", line 540, in main
iot_vwsfriendbackend.1.r9i5zbdfvrx4@srvnuc1    |     connector.commit()
iot_vwsfriendbackend.1.r9i5zbdfvrx4@srvnuc1    |   File "/opt/venv/lib/python3.12/site-packages/vwsfriend/agent_connector.py", line 133, in commit
iot_vwsfriendbackend.1.r9i5zbdfvrx4@srvnuc1    |     agent.commit()
iot_vwsfriendbackend.1.r9i5zbdfvrx4@srvnuc1    |   File "/opt/venv/lib/python3.12/site-packages/vwsfriend/agents/state_agent.py", line 99, in commit
iot_vwsfriendbackend.1.r9i5zbdfvrx4@srvnuc1    |     self.checkOnlineOffline()
iot_vwsfriendbackend.1.r9i5zbdfvrx4@srvnuc1    |   File "/opt/venv/lib/python3.12/site-packages/vwsfriend/agents/state_agent.py", line 84, in checkOnlineOffline
iot_vwsfriendbackend.1.r9i5zbdfvrx4@srvnuc1    |     with self.session.begin_nested():
iot_vwsfriendbackend.1.r9i5zbdfvrx4@srvnuc1    |          ^^^^^^^^^^^^^^^^^^^^^^^^^^^
iot_vwsfriendbackend.1.r9i5zbdfvrx4@srvnuc1    |   File "/opt/venv/lib/python3.12/site-packages/sqlalchemy/engine/util.py", line 147, in __exit__
iot_vwsfriendbackend.1.r9i5zbdfvrx4@srvnuc1    |     with util.safe_reraise():
iot_vwsfriendbackend.1.r9i5zbdfvrx4@srvnuc1    |          ^^^^^^^^^^^^^^^^^^^
iot_vwsfriendbackend.1.r9i5zbdfvrx4@srvnuc1    |   File "/opt/venv/lib/python3.12/site-packages/sqlalchemy/util/langhelpers.py", line 146, in __exit__
iot_vwsfriendbackend.1.r9i5zbdfvrx4@srvnuc1    |     raise exc_value.with_traceback(exc_tb)
iot_vwsfriendbackend.1.r9i5zbdfvrx4@srvnuc1    |   File "/opt/venv/lib/python3.12/site-packages/sqlalchemy/engine/util.py", line 145, in __exit__
iot_vwsfriendbackend.1.r9i5zbdfvrx4@srvnuc1    |     self.commit()
iot_vwsfriendbackend.1.r9i5zbdfvrx4@srvnuc1    |   File "<string>", line 2, in commit
iot_vwsfriendbackend.1.r9i5zbdfvrx4@srvnuc1    |   File "/opt/venv/lib/python3.12/site-packages/sqlalchemy/orm/state_changes.py", line 139, in _go
iot_vwsfriendbackend.1.r9i5zbdfvrx4@srvnuc1    |     ret_value = fn(self, *arg, **kw)
iot_vwsfriendbackend.1.r9i5zbdfvrx4@srvnuc1    |                 ^^^^^^^^^^^^^^^^^^^^
iot_vwsfriendbackend.1.r9i5zbdfvrx4@srvnuc1    |   File "/opt/venv/lib/python3.12/site-packages/sqlalchemy/orm/session.py", line 1313, in commit
iot_vwsfriendbackend.1.r9i5zbdfvrx4@srvnuc1    |     self._prepare_impl()
iot_vwsfriendbackend.1.r9i5zbdfvrx4@srvnuc1    |   File "<string>", line 2, in _prepare_impl
iot_vwsfriendbackend.1.r9i5zbdfvrx4@srvnuc1    |   File "/opt/venv/lib/python3.12/site-packages/sqlalchemy/orm/state_changes.py", line 139, in _go
iot_vwsfriendbackend.1.r9i5zbdfvrx4@srvnuc1    |     ret_value = fn(self, *arg, **kw)
iot_vwsfriendbackend.1.r9i5zbdfvrx4@srvnuc1    |                 ^^^^^^^^^^^^^^^^^^^^
iot_vwsfriendbackend.1.r9i5zbdfvrx4@srvnuc1    |   File "/opt/venv/lib/python3.12/site-packages/sqlalchemy/orm/session.py", line 1288, in _prepare_impl
iot_vwsfriendbackend.1.r9i5zbdfvrx4@srvnuc1    |     self.session.flush()
iot_vwsfriendbackend.1.r9i5zbdfvrx4@srvnuc1    |   File "/opt/venv/lib/python3.12/site-packages/sqlalchemy/orm/session.py", line 4352, in flush
iot_vwsfriendbackend.1.r9i5zbdfvrx4@srvnuc1    |     self._flush(objects)
iot_vwsfriendbackend.1.r9i5zbdfvrx4@srvnuc1    |   File "/opt/venv/lib/python3.12/site-packages/sqlalchemy/orm/session.py", line 4487, in _flush
iot_vwsfriendbackend.1.r9i5zbdfvrx4@srvnuc1    |     with util.safe_reraise():
iot_vwsfriendbackend.1.r9i5zbdfvrx4@srvnuc1    |          ^^^^^^^^^^^^^^^^^^^
iot_vwsfriendbackend.1.r9i5zbdfvrx4@srvnuc1    |   File "/opt/venv/lib/python3.12/site-packages/sqlalchemy/util/langhelpers.py", line 146, in __exit__
iot_vwsfriendbackend.1.r9i5zbdfvrx4@srvnuc1    |     raise exc_value.with_traceback(exc_tb)
iot_vwsfriendbackend.1.r9i5zbdfvrx4@srvnuc1    |   File "/opt/venv/lib/python3.12/site-packages/sqlalchemy/orm/session.py", line 4448, in _flush
iot_vwsfriendbackend.1.r9i5zbdfvrx4@srvnuc1    |     flush_context.execute()
iot_vwsfriendbackend.1.r9i5zbdfvrx4@srvnuc1    |   File "/opt/venv/lib/python3.12/site-packages/sqlalchemy/orm/unitofwork.py", line 466, in execute
iot_vwsfriendbackend.1.r9i5zbdfvrx4@srvnuc1    |     rec.execute(self)
iot_vwsfriendbackend.1.r9i5zbdfvrx4@srvnuc1    |   File "/opt/venv/lib/python3.12/site-packages/sqlalchemy/orm/unitofwork.py", line 642, in execute
iot_vwsfriendbackend.1.r9i5zbdfvrx4@srvnuc1    |     util.preloaded.orm_persistence.save_obj(
iot_vwsfriendbackend.1.r9i5zbdfvrx4@srvnuc1    |   File "/opt/venv/lib/python3.12/site-packages/sqlalchemy/orm/persistence.py", line 85, in save_obj
iot_vwsfriendbackend.1.r9i5zbdfvrx4@srvnuc1    |     _emit_update_statements(
iot_vwsfriendbackend.1.r9i5zbdfvrx4@srvnuc1    |   File "/opt/venv/lib/python3.12/site-packages/sqlalchemy/orm/persistence.py", line 948, in _emit_update_statements
iot_vwsfriendbackend.1.r9i5zbdfvrx4@srvnuc1    |     raise orm_exc.StaleDataError(
iot_vwsfriendbackend.1.r9i5zbdfvrx4@srvnuc1    | sqlalchemy.orm.exc.StaleDataError: UPDATE statement on table 'vehicles' expected to update 1 row(s); 2 were matched.

So I connected directly to the database :

        vin        |       model        |               nickname               | carType | online |         lastUpdate         |     lastChange      
-------------------+--------------------+--------------------------------------+---------+--------+----------------------------+---------------------
 WVWZZZXXXXXXXXX93 | Passat Variant GTE | Passat GTE Wagon . 1.4 l eHybrid GPF | HYBRID  | f      | 2024-10-16 08:32:11.306816 | 2024-10-16 04:00:30
 WVWZZZXXXXXXXXX93 | Passat Variant GTE | Passat GTE Wagon . 1.4 l eHybrid GPF | HYBRID  | t      | 2024-10-21 22:59:42.994754 | 2024-10-21 22:55:00
(2 rows)

I deleted one of them using
DELETE FROM "vehicles" WHERE online = 'f';

And restarted the container so that everything came back to normal.

@tillsteinbach
Copy link
Owner

huh, hard to understand how this can happen. The vin is the primary key and should be unique.

@scantineau
Copy link
Author

Agree. This should not happen but if someone has the same trouble, the solution is here too.
I don't think this issue needs to be investigated further and so, probably may be closed.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants