Skip to content

Expose API responses in deploy_with_config for both success and failure scenarios #695

@akhilannan

Description

@akhilannan

What is the feature?

The Gap:
When using deploy_with_config, the FabricWorkspace object is instantiated internally within the function scope.

  1. On Success: The function returns None, swallowing the responses dictionary (when enable_response_collection is active).
  2. On Failure: The function raises an exception immediately. Because the FabricWorkspace object is local to the function scope, it is destroyed when the stack unwinds. The caller has no way to access workspace.responses to determine which items succeeded before the crash.

This makes deploy_with_config unsuitable for production pipelines where reporting partial success (e.g., "Notebooks deployed, but Pipelines failed") is required.

The Ideal Solution:
Modify deploy_with_config in src/fabric_cicd/publish.py to wrap the operations in a try...except block.

  1. Happy Path: Return workspace.responses.
  2. Failure Path: Catch the exception, attach the workspace.responses dictionary to the Exception instance (e.g., as a .partial_results attribute), and re-raise the exception.

Proposed Implementation Logic:

# src/fabric_cicd/publish.py

def deploy_with_config(...):
    # ... setup workspace ...
    
    try:
        # Execute deployment operations
        if not publish_settings.get("skip", False):
            publish_all_items(workspace, ...)
            
        if not unpublish_settings.get("skip", False):
            unpublish_all_orphan_items(workspace, ...)
            
    except Exception as e:
        # Attach partial responses to the exception object before re-raising
        # This preserves the data that would otherwise be lost when 'workspace' goes out of scope
        if hasattr(workspace, 'responses') and workspace.responses:
            # Dynamically attach attribute to exception instance
            e.partial_results = workspace.responses
        raise e
        
    # Happy path return
    return getattr(workspace, 'responses', None)

Additional context

Example Usage if implemented:

from fabric_cicd import deploy_with_config, append_feature_flag

append_feature_flag("enable_response_collection")
# ... enable other flags ...

try:
    results = deploy_with_config(config_file_path="config.yml", environment="PROD")
    print("Deployment Success!")
    # Process results (e.g. log new Item IDs)
    if results:
        print(results)

except Exception as e:
    print("Deployment Failed!")
    
    # Feature allows accessing partial data attached to the exception
    if hasattr(e, 'partial_results'):
        print("Items that succeeded before crash:")
        for item_type, items in e.partial_results.items():
            print(f"- {item_type}: {list(items.keys())}")
            
    raise e # Fail the pipeline

Metadata

Metadata

Assignees

No one assigned

    Labels

    enhancementNew feature or request

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions