danylokhodus commited on
Commit
8b1a825
·
1 Parent(s): 46fc486

fix: resolve foreign key constraint error when saving edges

Browse files
FlowAPI.Infrastructure/Repositories/GraphRepository.cs CHANGED
@@ -109,11 +109,13 @@ namespace FlowAPI.Infrastructure.Repositories
109
  }
110
  }
111
 
 
 
112
  // 4. Update or Create Edges
113
  foreach (var edge in incomingEdges)
114
  {
115
- // Only create edge if it wasn't deleted (i.e. not connected to a deleted node)
116
- if (deletedNodeIds.Contains(edge.FromNodeId) || deletedNodeIds.Contains(edge.ToNodeId))
117
  {
118
  continue;
119
  }
 
109
  }
110
  }
111
 
112
+ var incomingNodeIds = incomingNodes.Select(n => n.Id).ToHashSet();
113
+
114
  // 4. Update or Create Edges
115
  foreach (var edge in incomingEdges)
116
  {
117
+ // Only create/update edge if both FromNode and ToNode exist in the incoming nodes list
118
+ if (!incomingNodeIds.Contains(edge.FromNodeId) || !incomingNodeIds.Contains(edge.ToNodeId))
119
  {
120
  continue;
121
  }
FlowAPI/inspect_db.py CHANGED
@@ -1,15 +1,30 @@
1
  import sqlite3
2
- conn = sqlite3.connect('taskflow.db')
3
- cursor = conn.cursor()
4
 
5
- print("--- All TaskNodes ---")
6
- nodes = cursor.execute("SELECT * FROM TaskNodes").fetchall()
7
- for n in nodes:
8
- print(n)
9
 
10
- print("\n--- All Edges ---")
11
- edges = cursor.execute("SELECT * FROM Edges").fetchall()
12
- for e in edges:
13
- print(e)
 
 
14
 
15
- conn.close()
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
  import sqlite3
 
 
2
 
3
+ def inspect():
4
+ conn = sqlite3.connect('taskflow.db')
5
+ cursor = conn.cursor()
 
6
 
7
+ print("=== Table Schemas ===")
8
+ tables = cursor.execute("SELECT name, sql FROM sqlite_master WHERE type='table'").fetchall()
9
+ for name, sql in tables:
10
+ print(f"Table: {name}")
11
+ print(sql)
12
+ print("-" * 50)
13
 
14
+ print("\n=== Foreign Key Check ===")
15
+ try:
16
+ # PRAGMA foreign_key_check lists all foreign key violations
17
+ violations = cursor.execute("PRAGMA foreign_key_check").fetchall()
18
+ if violations:
19
+ print("Found foreign key violations:")
20
+ for v in violations:
21
+ print(f"Table: {v[0]}, RowId: {v[1]}, Target Table: {v[2]}, Fk Index: {v[3]}")
22
+ else:
23
+ print("No foreign key violations in the current database.")
24
+ except Exception as e:
25
+ print(f"Error checking foreign keys: {e}")
26
+
27
+ conn.close()
28
+
29
+ if __name__ == '__main__':
30
+ inspect()