Skip to content

Closes #904 - Add Lakehouse Shortcuts Smart Publishing Feature#916

Open
bckstrm wants to merge 1 commit into
microsoft:mainfrom
bckstrm:shortcut_smart_diff
Open

Closes #904 - Add Lakehouse Shortcuts Smart Publishing Feature#916
bckstrm wants to merge 1 commit into
microsoft:mainfrom
bckstrm:shortcut_smart_diff

Conversation

@bckstrm
Copy link
Copy Markdown
Contributor

@bckstrm bckstrm commented Apr 1, 2026

This PR implements new feature flag ENABLE_SHORTCUT_SMART_DIFF which optimizes ShortcutPublisher.publish_all() in _lakehouse.py by avoiding unnecessary republishes of shortcuts that are already deployed and whose definitions have not changed.

Previously, publish_all() republished every shortcut on each run, even when the deployed shortcut already matched the desired state. In environments with many shortcuts, this led to unnecessary API calls and longer deployment times.

With this change, the workflow compares the local shortcut definition against deployed_shortcuts and only republishes shortcuts when a change is detected.

Linked Issue (REQUIRED)

#904

@bckstrm
Copy link
Copy Markdown
Contributor Author

bckstrm commented Apr 1, 2026

@microsoft-github-policy-service agree

@bckstrm bckstrm force-pushed the shortcut_smart_diff branch from 858e832 to 9dc4339 Compare April 1, 2026 11:38
Copy link
Copy Markdown
Contributor

@shirasassoon shirasassoon left a comment

Choose a reason for hiding this comment

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

Since there is a new feature flag, it should be documented in optional_features.md, the new flag and description should be added to the table, however, you can also add a paragraph under the selective deployment features to provide additional information.

ENABLE_SHORTCUT_PUBLISH = "enable_shortcut_publish"
"""Set to enable deploying shortcuts with the lakehouse."""
ENABLE_SHORTCUT_SMART_DIFF = "enable_shortcut_smart_diff"
"""Set to enable change comparision before deploying shortcuts"""
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

typo - comparison

logger.info(f"Publishing Lakehouse '{self.item_obj.name}' Shortcuts")
shortcut_paths_to_unpublish = [path for path in deployed_shortcuts if path not in shortcuts_to_publish]
shortcut_paths_to_unpublish = [
path for path in list(deployed_shortcuts.keys()) if path not in shortcuts_to_publish
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

not needed as dicts are directly iterable:

shortcut_paths_to_unpublish = [path for path in deployed_shortcuts if ...]

ShortcutPublisher(mock_fabric_workspace, mock_item).publish_all()

post_calls = get_shortcut_post_calls(mock_fabric_workspace)
assert len(post_calls) == 1
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

There's no test verifying that a brand-new shortcut (present in repo, absent from deployed) is always published even with smart diff enabled.

yield
constants.FEATURE_FLAG.clear()
constants.FEATURE_FLAG.update(original_flags)

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

The fixture is created, but not used anywhere - either remove or use it instead of try/finally

shortcuts_to_publish = {_get_shortcut_path(shortcut): shortcut for shortcut in shortcuts}

if shortcuts_to_publish:
logger.info(f"Publishing Lakehouse '{self.item_obj.name}' Shortcuts")
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

This logging can be misleading if all shortcuts are skipped, might make more sense to move it after the if FeatureFlag.ENALE_SHORTCUT_SMART_DIFF.value in constants.FEATURE_FLAG: block

True when the shortcut differs from deployed state and should be published.
"""
shortcut_for_compare = replace_default_lakehouse_id(copy.deepcopy(shortcut), self.item_obj)
return not self._is_shortcut_subset_match(shortcut_for_compare, deployed_shortcut)
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

deepcopy can add more overhead than necessary when multiple shortcuts are present, might make sense to use a targeted approach.

]
self._unpublish_shortcuts(shortcut_paths_to_unpublish)
# Deploy and overwrite shortcuts
if FeatureFlag.ENABLE_SHORTCUT_SMART_DIFF.value in constants.FEATURE_FLAG:
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

This flag technically only works when the feature flag enable_shortcut_publish is also present in the deployment - we need to clearly document that both must be enabled for this feature to work

@shirasassoon
Copy link
Copy Markdown
Contributor

@bckstrm Thanks for the contribution! Please see my review comments and resolve the conflicts as well. Thanks

@shirasassoon
Copy link
Copy Markdown
Contributor

@bckstrm Reminder this PR has comments for you to review, if we don't hear from you then we will close it.

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.

2 participants