Skip to content

[Server] Fix function ownership transfer for functions with properties - #2319

Merged
yili-db merged 1 commit into
unitycatalog:mainfrom
maharanay22:fix-function-owner-update-with-properties
Nov 20, 2026
Merged

yili-db merged 1 commit into
unitycatalog:mainfrom
maharanay22:fix-function-owner-update-with-properties

Conversation

@maharanay22

Copy link
Copy Markdown
Contributor

PR Checklist

  • A description of the changes is added to the description of this PR.
  • If there is a related issue, make sure it is linked to this PR.
  • 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

Transferring ownership of a function that has properties fails with a 500. For example, after creating main.default.fn with properties set to {"team":"ml"}, PATCH /api/2.1/unity-catalog/functions/main.default.fn with {"owner": "[email protected]"} returns INTERNAL "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 a setProperties(Map) method by reflection, but FunctionInfo.properties is a JSON string. #2149 was written while attachProperties still 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 on main every transfer of a function stored with properties hits the Map lookup and fails.

The fix renders the update response's properties the same way getFunction and listFunctions do, so a transfer returns the same properties JSON as a later get. The stored properties are not touched by the update. The other callers of attachProperties pass catalogs, schemas and tables, whose properties are maps, so they are unaffected.

Tests

OwnershipRepositoryTest.functionTransferKeepsProperties transfers a function stored with properties. It checks that the new owner is saved and holds the only OWNER grant, that getFunction still returns the original properties, and that the update response returns the same properties. It fails on main with the NoSuchMethodException above, 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 do server/javafmtCheckAll and the checkstyle tasks. The change has no SQL of its own, so MySQL and PostgreSQL run in CI.

@yili-db

yili-db commented Nov 20, 2026

Copy link
Copy Markdown
Collaborator

/review

@yili-db yili-db left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

[AI Assisted] Approving at 99d16b5.

  • The fix is in FunctionRepository.updateFunction. It uses the same setProperties helper that getFunction and listFunctions already use, so the update response matches a later get.
  • Verified: with the fix, OwnershipRepositoryTest, SdkFunctionCRUDTest, and SdkFunctionAccessControlCRUDTest pass (24 of 24). With the base FunctionRepository.java restored, functionTransferKeepsProperties fails with the NoSuchMethodException from the description.
  • Authorization is unchanged, and the other securables with properties (catalog, schema, table) use map types that attachProperties already handles.

@yili-db
yili-db merged commit 1a937bf into unitycatalog:main Nov 20, 2026
27 checks passed

@timothyw553 timothyw553 left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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(

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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?

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Good idea, thanks. Done in #2326: attachProperties now takes a typed BiConsumer setter like CatalogInfo::setProperties, so passing FunctionInfo::setProperties fails at compile time.

yili-db pushed a commit that referenced this pull request Nov 20, 2026
…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]>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants