Skip to content

Feature/project importer overwrite#5

Merged
privateip merged 4 commits intodevelfrom
feature/project-importer-overwrite
Feb 4, 2026
Merged

Feature/project importer overwrite#5
privateip merged 4 commits intodevelfrom
feature/project-importer-overwrite

Conversation

@jennlu330
Copy link
Contributor

Description

Add an optional overwrite parameter to the projects.importer() method to support overwriting existing projects during import operations.

Motivation

When promoting projects across environments (development → staging → production), teams often need to update existing projects rather than create new ones. The current importer() method raises an AsyncPlatformError if a project with the same name already exists, requiring users to manually delete the project before re-importing.

This workflow is cumbersome for CI/CD pipelines and automated deployment scripts where you want to promote the latest version of a project without manual intervention.

Changes

Core Functionality

  • Added overwrite: bool = False parameter to the importer() method
  • When overwrite=True: finds and deletes any existing project with the same name before importing
  • When overwrite=False (default): maintains current behavior of raising an error if project exists
  • Updated method docstring with comprehensive parameter documentation

Implementation Details

  • Uses existing find_projects() and delete_project() methods for cleanup
  • Backward compatible - default value of False preserves existing behavior
  • Only searches/deletes when overwrite=True to minimize unnecessary API calls

Test Coverage

Added 5 comprehensive test cases:

  1. test_importer_with_overwrite_true_deletes_existing - Verifies deletion and re-import when project exists
  2. test_importer_with_overwrite_true_no_existing_project - Verifies normal import when no conflict
  3. test_importer_with_overwrite_false_raises_on_existing - Verifies error raised with explicit overwrite=False
  4. test_importer_overwrite_default_false - Verifies default parameter value maintains backward compatibility
  5. Formatting fixes applied via ruff

Testing Performed

  • All 506 tests pass (including 5 new tests for this feature)
  • Linting checks pass: uv run ruff check
  • Type checking passes: uv run mypy
  • Code formatting applied: uv run ruff format
  • Tested in production deployment pipeline with real projects
  • Verified backward compatibility - existing code without overwrite parameter works unchanged

Example Usage

import asyncplatform
from asyncplatform.models.projects import ProjectMember

async with asyncplatform.client(host="...", client_id="...", client_secret="...") as client:
    projects = client.resource("projects")
    
    # Load project data
    with open("project.json") as f:
        project_data = json.load(f)
    
    # Import with overwrite - will replace existing project if present
    result = await projects.importer(
        project_data,
        members=[ProjectMember(username="admin", type="account", role="owner")],
        overwrite=True  # New parameter
    )

Copy link
Member

@privateip privateip left a comment

Choose a reason for hiding this comment

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

Looks like you have some linting failures. Please clean those up so this PR can be merged.

@jennlu330
Copy link
Contributor Author

@privateip Updated the help.py file and fixed the linting issues:

  1. Added the type annotation str | None to the url parameter
  2. Removed an unused import asyncio import

@privateip privateip merged commit ffcc1cc into devel Feb 4, 2026
3 checks passed
@privateip privateip deleted the feature/project-importer-overwrite branch February 4, 2026 18:01
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