Repository navigation
Conversation
Signed-off-by: Maha Rana Yadavalli <[email protected]>
|
/review |
yili-db
left a comment
There was a problem hiding this comment.
[AI Assisted] Approving at 99d16b5.
- The fix is in
FunctionRepository.updateFunction. It uses the samesetPropertieshelper thatgetFunctionandlistFunctionsalready use, so the update response matches a later get. - Verified: with the fix,
OwnershipRepositoryTest,SdkFunctionCRUDTest, andSdkFunctionAccessControlCRUDTestpass (24 of 24). With the baseFunctionRepository.javarestored,functionTransferKeepsPropertiesfails with theNoSuchMethodExceptionfrom the description. - Authorization is unchanged, and the other securables with properties (catalog, schema, table) use map types that
attachPropertiesalready handles.
timothyw553
left a comment
There was a problem hiding this comment.
overall LGTM, the fix and regression test look solid. left a few small nits for follow-up, nothing blocking.
| dao.setUpdatedBy(IdentityUtils.findPrincipalEmailAddress()); | ||
| FunctionInfo result = dao.toFunctionInfo(); | ||
| addNamespaceInfo(result, parts[0], parts[1]); | ||
| return RepositoryUtils.attachProperties( |
There was a problem hiding this comment.
nit: unrelated to fixing this bug, but RepositoryUtils.attachProperties uses reflection and only fails when property rows exist. in a follow-up, should we pass a typed BiConsumer<T, Map<String, String>> setter (like CatalogInfo::setProperties) so incompatible models fail at compile time?
There was a problem hiding this comment.
Good idea, thanks. Done in #2326: attachProperties now takes a typed BiConsumer setter like CatalogInfo::setProperties, so passing FunctionInfo::setProperties fails at compile time.
…erties (#2326) **PR Checklist** - [x] A description of the changes is added to the description of this PR. - [x] If there is a related issue, make sure it is linked to this PR. - [x] If you've fixed a bug or added code that should be tested, add tests! - [ ] If you've added or modified a feature, documentation in `docs` is updated **Description of changes** This follows up on #2319, as suggested in its review. `RepositoryUtils.attachProperties` looked up `setProperties(Map)` on the model by reflection, so a model whose properties aren't a map compiled fine and then failed at runtime, and only once the entity had property rows. That is how a function transfer failed with `NoSuchMethodException` before #2319, because `FunctionInfo.properties` is a JSON string. Callers now pass the setter as a method reference, for example `CatalogInfo::setProperties`, typed as `BiConsumer<T, Map<String, String>>`. Passing `FunctionInfo::setProperties` no longer compiles, so that mistake shows up at build time. The reflection and its exception wrapping are removed. The property lookup is unchanged, and the model is still left untouched when there are no property rows, so API responses don't change. `SchemaRepository.getSchema` attached the properties a second time after `convertFromDAO` had already done it, so that redundant call is removed. **Tests** `RepositoriesTest.catalogSchemaAndTableReadsAttachTheirProperties` stores a catalog, a schema and a table with different properties, and checks that get, list and update for catalogs and schemas, and get and owner update for tables, return each entity's own properties. Replacing the setter with a no-op at any call site makes it fail. A scratch call passing `FunctionInfo::setProperties` failed `server/compile` with "incompatible types: invalid method reference". `build/sbt "server/testOnly io.unitycatalog.server.persist.RepositoriesTest io.unitycatalog.server.persist.OwnershipRepositoryTest io.unitycatalog.server.persist.utils.RepositoryUtilsTest"` passes on H2 on Windows with JDK 17, and so do `server/javafmtCheckAll` and checkstyle. The change has no SQL, so MySQL and PostgreSQL run in CI. Signed-off-by: Maha Rana Yadavalli <[email protected]> Co-authored-by: Maha Rana Yadavalli <[email protected]>
PR Checklist
docsis updatedDescription of changes
Transferring ownership of a function that has properties fails with a 500. For example, after creating
main.default.fnwithpropertiesset to{"team":"ml"},PATCH /api/2.1/unity-catalog/functions/main.default.fnwith{"owner": "[email protected]"}returnsINTERNAL"Failed to update function: java.lang.NoSuchMethodException: io.unitycatalog.server.model.FunctionInfo.setProperties(java.util.Map)". The transaction rolls back, so the owner and the OWNER grant stay with the previous owner, and the function can't be transferred while it has properties. Functions without properties are not affected.The function update added in #2149 builds its response with
RepositoryUtils.attachProperties. That helper looks up asetProperties(Map)method by reflection, butFunctionInfo.propertiesis a JSON string. #2149 was written whileattachPropertiesstill had a special case for functions, and #2233 removed that special case after function properties moved to their own JSON rendering and nothing else called it for functions. The two PRs merged in the opposite order, so onmainevery transfer of a function stored with properties hits theMaplookup and fails.The fix renders the update response's properties the same way
getFunctionandlistFunctionsdo, so a transfer returns the same properties JSON as a later get. The stored properties are not touched by the update. The other callers ofattachPropertiespass catalogs, schemas and tables, whose properties are maps, so they are unaffected.Tests
OwnershipRepositoryTest.functionTransferKeepsPropertiestransfers a function stored with properties. It checks that the new owner is saved and holds the only OWNER grant, thatgetFunctionstill returns the original properties, and that the update response returns the same properties. It fails onmainwith theNoSuchMethodExceptionabove, and it also fails if the update response drops the properties.build/sbt "server/testOnly io.unitycatalog.server.persist.OwnershipRepositoryTest"passes on H2 on Windows with JDK 17, and so doserver/javafmtCheckAlland the checkstyle tasks. The change has no SQL of its own, so MySQL and PostgreSQL run in CI.