mirror of
https://github.com/qelectrotech/qelectrotech-source-mirror.git
synced 2026-09-28 04:54:13 +02:00
Fix element_info orphan row causing UNIQUE constraint errors on undo
Reviving #664, closed 2026-09-18 purely to clear a maintainer review backlog (#630), not on merit; not superseded. Rewritten fresh against current master rather than merged from the old branch -- that branch predates the Qt6-only switch and much of dataBase/projectdatabase.cpp's later rewrite, and the two had diverged too far for a textual merge to be trustworthy. projectDataBase::removeElement() only ran DELETE FROM element WHERE uuid=:uuid. It never touched element_info, even though every element also has a row there (element_uuid is its PRIMARY KEY, with a FOREIGN KEY back to element.uuid that isn't enforced by this connection -- no ON DELETE CASCADE in effect). So deleting an element left its element_info row orphaned. Re-adding an element with that same uuid later -- undo of that same deletion, or a redo replaying it -- goes through addElement(), which INSERTs into both tables. The element insert succeeds (that row really was removed). The element_info insert hits the orphaned row's primary key and fails, silently: the error is logged and swallowed, so the element re-enters the scene with no element_info row at all, and nothing later re-syncs it. removeDiagram() already cascades this cleanup when a whole folio is removed (a later, unrelated addition) -- confirmed on current master -- but that path never runs for a single element removed on its own, which is the case this fixes. Verified on the built binary, not just read: placed an element, deleted it (Ctrl+A, Delete), undid the deletion (Ctrl+Z). Reverting just this fix and repeating the identical sequence reproduces the exact reported error: Debug: projectDataBase::addElement insert element info error : QSqlError("1555", "Unable to fetch row", "UNIQUE constraint failed: element_info.element_uuid") With the fix, the same sequence produces nothing. Qt 6.10.2, ctest 13/13. Co-Authored-By: Claude Sonnet 5 <noreply@anthropic.com>
This commit is contained in:
@@ -139,6 +139,7 @@ class projectDataBase : public QObject
|
||||
QSqlQuery m_insert_elements_query,
|
||||
m_insert_element_info_query,
|
||||
m_remove_element_query,
|
||||
m_remove_element_info_query,
|
||||
m_update_element_query,
|
||||
m_insert_diagram_query,
|
||||
m_remove_diagram_query,
|
||||
|
||||
Reference in New Issue
Block a user