HonahX opened a new pull request, #3219:
URL: https://github.com/apache/polaris/pull/3219

   <!--
   ๐Ÿ“ Describe what changes you're proposing, especially breaking or user-facing 
changes. 
   ๐Ÿ“– See https://github.com/apache/polaris/blob/main/CONTRIBUTING.md for more.
   -->
   In TransactionalMetaStoreManagerImpl.createEntitiesIfNotExist, we currently 
directly return the entity received in the arg if the entity does not exist:
   
   
https://github.com/apache/polaris/blob/be3c88b6d057009a05301a25ef99b775604955ea/polaris-core/src/main/java/org/apache/polaris/core/persistence/transactional/TransactionalMetaStoreManagerImpl.java#L1087-L1091
   
   However, the `persistNewEntity` above will update some field including 
`lastUpdatedTimestamp` before writing the entity
   
https://github.com/apache/polaris/blob/be3c88b6d057009a05301a25ef99b775604955ea/polaris-core/src/main/java/org/apache/polaris/core/persistence/BaseMetaStoreManager.java#L108-L111
   
   As a result, the entity included in the `EntityResult` is not the same as 
the actual entity persisted.
   
   The similar issue also happened in `CreatePrincipal`.
   
   ### How to reproduce
   ```java
   PolarisMetaStoreManager metaStoreManager = 
polarisTestMetaStoreManager.polarisMetaStoreManager;
       PolarisCallContext callCtx = 
polarisTestMetaStoreManager.polarisCallContext;
       PolarisBaseEntity principalEntity =
           metaStoreManager
               .createPrincipal(
                   callCtx,
                   new PrincipalEntity.Builder()
                       
.setId(metaStoreManager.generateNewEntityId(callCtx).getId())
                       .setName("principal_test")
                       .setCreateTimestamp(100L)
                       .build())
               .getPrincipal();
   
       PolarisBaseEntity fetchedPrincipal =
           metaStoreManager
               .readEntityByName(
                   callCtx,
                   null,
                   PolarisEntityType.PRINCIPAL,
                   PolarisEntitySubType.NULL_SUBTYPE,
                   "principal_test")
               .getEntity();
        
       // The assertion will fail because the principalEntity have 
lastUpdatedTimestamp = 0 while fetchedPrincipal have lastUpdatedTimestamp = 100L
       Assertions.assertThat(principalEntity).isEqualTo(fetchedPrincipal);
   ```
   
   ### Fix
   The PR fixes the issue by letting `persistEntity` return the entity 
persisted and include that in the EntityResult. The PR also include new unit 
tests to verify the behavior
   
   ## Checklist
   - [ ] ๐Ÿ›ก๏ธ Don't disclose security issues! (contact [email protected])
   - [ ] ๐Ÿ”— Clearly explained why the changes are needed, or linked related 
issues: Fixes #
   - [ ] ๐Ÿงช Added/updated tests with good coverage, or manually tested (and 
explained how)
   - [ ] ๐Ÿ’ก Added comments for complex logic
   - [ ] ๐Ÿงพ Updated `CHANGELOG.md` (if needed)
   - [ ] ๐Ÿ“š Updated documentation in `site/content/in-dev/unreleased` (if needed)
   


-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: [email protected]

For queries about this service, please contact Infrastructure at:
[email protected]

Reply via email to