mirror of
				https://github.com/open-metadata/OpenMetadata.git
				synced 2025-10-31 10:39:30 +00:00 
			
		
		
		
	Minor: Fix NPE for botUser during race Condition, Timestamp Comparison (#23660)
* Fix NPE for botUser during race Condition * Fix Timestamp processing for date assertions
This commit is contained in:
		
							parent
							
								
									453c57df9f
								
							
						
					
					
						commit
						2cf7466911
					
				| @ -52,7 +52,17 @@ public class BotRepository extends EntityRepository<Bot> { | |||||||
| 
 | 
 | ||||||
|   @Override |   @Override | ||||||
|   public void prepare(Bot entity, boolean update) { |   public void prepare(Bot entity, boolean update) { | ||||||
|     User user = Entity.getEntity(entity.getBotUser(), "", Include.ALL); |     EntityReference botUserRef = entity.getBotUser(); | ||||||
|  |     if (botUserRef == null) { | ||||||
|  |       // Race condition detected: Retry by fetching the relationship directly from the database | ||||||
|  |       botUserRef = getBotUser(entity); | ||||||
|  |     } | ||||||
|  |     if (botUserRef == null) { | ||||||
|  |       // This should never happen | ||||||
|  |       throw new IllegalStateException( | ||||||
|  |           String.format("Bot entity [%s] is missing required botUser reference", entity.getId())); | ||||||
|  |     } | ||||||
|  |     User user = Entity.getEntity(botUserRef, "", Include.ALL); | ||||||
|     entity.withBotUser(user.getEntityReference()); |     entity.withBotUser(user.getEntityReference()); | ||||||
|   } |   } | ||||||
| 
 | 
 | ||||||
|  | |||||||
| @ -4497,11 +4497,18 @@ public abstract class EntityResourceTest<T extends EntityInterface, K extends Cr | |||||||
|             .withConfigType(SettingsType.ASSET_CERTIFICATION_SETTINGS) |             .withConfigType(SettingsType.ASSET_CERTIFICATION_SETTINGS) | ||||||
|             .withConfigValue(certificationSettings)); |             .withConfigValue(certificationSettings)); | ||||||
| 
 | 
 | ||||||
|  |     long timestampBeforePatch = System.currentTimeMillis(); | ||||||
|     T patchedEntity = patchEntity(entity.getId(), json, entity, ADMIN_AUTH_HEADERS); |     T patchedEntity = patchEntity(entity.getId(), json, entity, ADMIN_AUTH_HEADERS); | ||||||
|  |     long timestampAfterPatch = System.currentTimeMillis(); | ||||||
|     assertEquals( |     assertEquals( | ||||||
|         patchedEntity.getCertification().getTagLabel().getTagFQN(), certificationLabel.getTagFQN()); |         patchedEntity.getCertification().getTagLabel().getTagFQN(), certificationLabel.getTagFQN()); | ||||||
|     assertEquals( |     // Verify the applied date is within the time window of the patch operation | ||||||
|         patchedEntity.getCertification().getAppliedDate(), System.currentTimeMillis(), 10 * 1000); |     assertTrue( | ||||||
|  |         patchedEntity.getCertification().getAppliedDate() >= timestampBeforePatch - 1000, | ||||||
|  |         "Applied date should be at or after the patch operation started (with 1s tolerance)"); | ||||||
|  |     assertTrue( | ||||||
|  |         patchedEntity.getCertification().getAppliedDate() <= timestampAfterPatch + 1000, | ||||||
|  |         "Applied date should be at or before the patch operation completed (with 1s tolerance)"); | ||||||
|     assertEquals( |     assertEquals( | ||||||
|         (double) |         (double) | ||||||
|             (patchedEntity.getCertification().getExpiryDate() |             (patchedEntity.getCertification().getExpiryDate() | ||||||
|  | |||||||
		Loading…
	
	
			
			x
			
			
		
	
		Reference in New Issue
	
	Block a user
	 Ram Narayan Balaji
						Ram Narayan Balaji