Skip to content

Commit 2276f8a

Browse files
authored
FIX - Missing service when preparing deploy during PATCH (#25984)
* FIX - Missing service when preparing deploy during PATCH * FIX - Missing service when preparing deploy during PATCH
1 parent 6724762 commit 2276f8a

File tree

2 files changed

+64
-0
lines changed

2 files changed

+64
-0
lines changed

openmetadata-service/src/main/java/org/openmetadata/service/jdbi3/IngestionPipelineRepository.java

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -283,6 +283,23 @@ boolean hasSourceConfigChanged(IngestionPipeline original, IngestionPipeline upd
283283
protected void deployPipelineBeforeUpdate(IngestionPipeline ingestionPipeline) {
284284
IngestionPipeline decrypted = buildIngestionPipelineDecrypted(ingestionPipeline);
285285

286+
// Restore service reference lost during JSON round-trip (service is a relationship,
287+
// not stored in the entity JSON). Fall back to fetching from the relationships table.
288+
if (decrypted.getService() == null) {
289+
EntityReference serviceRef =
290+
ingestionPipeline.getService() != null
291+
? ingestionPipeline.getService()
292+
: getContainer(ingestionPipeline.getId());
293+
if (serviceRef == null) {
294+
throw new IllegalStateException(
295+
String.format(
296+
"Cannot deploy pipeline '%s': no service reference found. "
297+
+ "The pipeline may have a broken service relationship.",
298+
ingestionPipeline.getName()));
299+
}
300+
decrypted.setService(serviceRef);
301+
}
302+
286303
OpenMetadataConnection openMetadataServerConnection =
287304
new org.openmetadata.service.util.OpenMetadataConnectionBuilder(
288305
openMetadataApplicationConfig, decrypted)

openmetadata-service/src/test/java/org/openmetadata/service/jdbi3/IngestionPipelineRepositoryTest.java

Lines changed: 47 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,15 @@
11
package org.openmetadata.service.jdbi3;
22

3+
import static org.junit.jupiter.api.Assertions.assertEquals;
34
import static org.junit.jupiter.api.Assertions.assertFalse;
5+
import static org.junit.jupiter.api.Assertions.assertNotNull;
6+
import static org.junit.jupiter.api.Assertions.assertNull;
47
import static org.junit.jupiter.api.Assertions.assertTrue;
58
import static org.mockito.Mockito.mock;
69
import static org.mockito.Mockito.when;
710

811
import java.util.Objects;
12+
import java.util.UUID;
913
import org.junit.jupiter.api.BeforeAll;
1014
import org.junit.jupiter.api.DisplayName;
1115
import org.junit.jupiter.api.Test;
@@ -14,7 +18,10 @@
1418
import org.openmetadata.schema.metadataIngestion.DatabaseServiceMetadataPipeline;
1519
import org.openmetadata.schema.metadataIngestion.LogLevels;
1620
import org.openmetadata.schema.metadataIngestion.SourceConfig;
21+
import org.openmetadata.schema.security.secrets.SecretsManagerConfiguration;
22+
import org.openmetadata.schema.security.secrets.SecretsManagerProvider;
1723
import org.openmetadata.schema.type.EntityReference;
24+
import org.openmetadata.service.secrets.SecretsManagerFactory;
1825

1926
class IngestionPipelineRepositoryTest {
2027

@@ -31,6 +38,10 @@ static void setup() {
3138
org.mockito.ArgumentMatchers.any(IngestionPipeline.class),
3239
org.mockito.ArgumentMatchers.any(IngestionPipeline.class)))
3340
.thenCallRealMethod();
41+
42+
SecretsManagerConfiguration smConfig = new SecretsManagerConfiguration();
43+
smConfig.setSecretsManager(SecretsManagerProvider.DB);
44+
SecretsManagerFactory.createSecretsManager(smConfig, "test");
3445
}
3546

3647
@Test
@@ -219,6 +230,42 @@ void testHasSourceConfigChanged_OneNull_ShouldReturnTrue() {
219230
assertTrue(hasChanged, "Null to non-null sourceConfig should indicate a change");
220231
}
221232

233+
@Test
234+
@DisplayName(
235+
"buildIngestionPipelineDecrypted with null service should produce decrypted pipeline without service")
236+
void testBuildIngestionPipelineDecrypted_NullServicePreserved() {
237+
IngestionPipeline pipeline = createBasicPipeline();
238+
pipeline.setService(null);
239+
240+
IngestionPipeline decrypted =
241+
IngestionPipelineRepository.buildIngestionPipelineDecrypted(pipeline);
242+
243+
assertNull(
244+
decrypted.getService(),
245+
"Decrypted pipeline should have null service when original has null service."
246+
+ " This happens when the pipeline is loaded via findByName (service is a relationship"
247+
+ " field stripped before DB storage). deployPipelineBeforeUpdate must restore it.");
248+
}
249+
250+
@Test
251+
@DisplayName("buildIngestionPipelineDecrypted with service set should preserve it")
252+
void testBuildIngestionPipelineDecrypted_ServicePreserved() {
253+
UUID serviceId = UUID.randomUUID();
254+
EntityReference serviceRef = new EntityReference();
255+
serviceRef.setId(serviceId);
256+
serviceRef.setName("OpenMetadata");
257+
serviceRef.setType("metadataService");
258+
259+
IngestionPipeline pipeline = createBasicPipeline();
260+
pipeline.setService(serviceRef);
261+
262+
IngestionPipeline decrypted =
263+
IngestionPipelineRepository.buildIngestionPipelineDecrypted(pipeline);
264+
265+
assertNotNull(decrypted.getService());
266+
assertEquals("OpenMetadata", decrypted.getService().getName());
267+
}
268+
222269
private static IngestionPipeline createPipelineWithSchedule(String schedule) {
223270
IngestionPipeline pipeline = createBasicPipeline();
224271
AirflowConfig airflowConfig = new AirflowConfig();

0 commit comments

Comments
 (0)