diff --git a/airbyte-server/src/main/java/io/airbyte/server/handlers/WebBackendConnectionsHandler.java b/airbyte-server/src/main/java/io/airbyte/server/handlers/WebBackendConnectionsHandler.java index a3c3886807f3..ea3aad8a66d3 100644 --- a/airbyte-server/src/main/java/io/airbyte/server/handlers/WebBackendConnectionsHandler.java +++ b/airbyte-server/src/main/java/io/airbyte/server/handlers/WebBackendConnectionsHandler.java @@ -348,10 +348,7 @@ public WebBackendConnectionRead webBackendGetConnection(final WebBackendConnecti /* * constructs a full picture of all existing configured + all new / updated streams in the newest * catalog. - */ - syncCatalog = updateSchemaWithRefreshedDiscoveredCatalog(configuredCatalog, catalogUsedToMakeConfiguredCatalog.get(), - refreshedCatalog.get().getCatalog()); - /* + * * Diffing the catalog used to make the configured catalog gives us the clearest diff between the * schema when the configured catalog was made and now. In the case where we do not have the * original catalog used to make the configured catalog, we make due, but using the configured @@ -359,6 +356,9 @@ public WebBackendConnectionRead webBackendGetConnection(final WebBackendConnecti * but was present at time of configuration will appear in the diff as an added stream which is * confusing. We need to figure out why source_catalog_id is not always populated in the db. */ + syncCatalog = updateSchemaWithRefreshedDiscoveredCatalog(configuredCatalog, catalogUsedToMakeConfiguredCatalog.orElse(configuredCatalog), + refreshedCatalog.get().getCatalog()); + diff = refreshedCatalog.get().getCatalogDiff(); connection.setBreakingChange(refreshedCatalog.get().getBreakingChange()); connection.setStatus(refreshedCatalog.get().getConnectionStatus()); diff --git a/airbyte-server/src/test/java/io/airbyte/server/handlers/WebBackendConnectionsHandlerTest.java b/airbyte-server/src/test/java/io/airbyte/server/handlers/WebBackendConnectionsHandlerTest.java index 943cbfff5c13..b20c3b1fe4bf 100644 --- a/airbyte-server/src/test/java/io/airbyte/server/handlers/WebBackendConnectionsHandlerTest.java +++ b/airbyte-server/src/test/java/io/airbyte/server/handlers/WebBackendConnectionsHandlerTest.java @@ -456,6 +456,24 @@ void testWebBackendGetConnectionWithDiscoveryAndNewSchemaBreakingChange() throws assertEquals(expectedWithNewSchemaAndBreakingChange, result); } + @Test + void testWebBackendGetConnectionWithDiscoveryMissingCatalogUsedToMakeConfiguredCatalog() + throws IOException, ConfigNotFoundException, JsonValidationException { + final UUID newCatalogId = UUID.randomUUID(); + when(configRepository.getMostRecentActorCatalogFetchEventForSource(any())) + .thenReturn(Optional.of(new ActorCatalogFetchEvent().withActorCatalogId(newCatalogId))); + when(configRepository.getActorCatalogById(any())).thenReturn(new ActorCatalog().withId(UUID.randomUUID())); + final SourceDiscoverSchemaRead schemaRead = + new SourceDiscoverSchemaRead().catalogDiff(expectedWithNewSchema.getCatalogDiff()).catalog(expectedWithNewSchema.getSyncCatalog()) + .breakingChange(false).connectionStatus(ConnectionStatus.ACTIVE); + when(schedulerHandler.discoverSchemaForSourceFromSourceId(any())).thenReturn(schemaRead); + when(connectionsHandler.getConnectionAirbyteCatalog(connectionRead.getConnectionId())).thenReturn(Optional.empty()); + + final WebBackendConnectionRead result = testWebBackendGetConnection(true, connectionRead, + operationReadList); + assertEquals(expectedWithNewSchema, result); + } + @Test void testWebBackendGetConnectionWithDiscoveryAndFieldSelectionAddField() throws ConfigNotFoundException, IOException, JsonValidationException {