diff --git a/backend/app/services/device_discovery.py b/backend/app/services/device_discovery.py index 24aa85c..443bf81 100644 --- a/backend/app/services/device_discovery.py +++ b/backend/app/services/device_discovery.py @@ -433,4 +433,13 @@ async def discover_via_ssh( except Exception as exc: result.errors.append(f"Error upserting {found.ip}: {exc}") + # Flush after each rack so that subsequent SELECTs (for other racks + # that may share the same device IPs) see the just-added rows. + # Without this, autoflush=False means pending db.add() calls are + # invisible to SELECT queries, causing UniqueViolationError on flush. + try: + await db.flush() + except Exception as exc: + result.errors.append(f"Flush error after rack {rack_host}: {exc}") + return result