Skip to content

Fix review issues in migrate-users / create-workspaces PR#21

Merged
dsblank merged 2 commits intochasefortier/migrate-workspaces-and-usersfrom
dsblank/fix-migrate-users-pr20
Mar 25, 2026
Merged

Fix review issues in migrate-users / create-workspaces PR#21
dsblank merged 2 commits intochasefortier/migrate-workspaces-and-usersfrom
dsblank/fix-migrate-users-pr20

Conversation

@dsblank
Copy link
Copy Markdown
Collaborator

@dsblank dsblank commented Mar 13, 2026

User description

This PR addresses all issues identified in the code review of #20.

Changes

cometx/cli/copy.py

  • Move import requests to top-level (was inside try/except Exception, causing misleading error messages when requests wasn't installed)
  • Use self.api._get_url_server() instead of self.api.server_url (the server_url property requires _client and raises AttributeError)
  • Split the single except Exception into separate HTTPError and RequestException handlers so the error message includes the HTTP status code when available

cometx/cli/migrate_users.py

  • Add --url / --source-url args for self-hosted Comet instances whose API keys do not encode the server URL
  • Fix _resolve_server_url: add base64 padding, catch all decode errors gracefully, respect explicit URL arg with highest priority
  • Fix source_api_key fallback: no longer silently falls back to COMET_API_KEY--source-api-key is now required when --chargeback-report is not given; warn when source and dest URL+key are identical (likely a misconfiguration)
  • Fix _get_existing_workspaces: handle both flat-string list and dict-list API response shapes
  • Dry-run per-user output: print [DRY RUN] Would add 'email' to 'ws' for each user instead of only a count
  • Add --failures-output flag (default: bulk_add_failures_by_email.json) so the output path is configurable
  • Fix _add_member: use json=payload kwarg instead of data=json.dumps(payload)
  • Fix docstring examples: were using cometx --api-key ... migrate-users (global flag position) instead of cometx migrate-users --api-key ...

tests/unit/test_migrate_users.py (new)

17 unit tests covering:

  • _resolve_server_url — explicit URL, new-style key decoding, old-style key fallback, malformed key fallback
  • _get_existing_workspaces — flat list and dict-list responses
  • _add_member — success, already-member, failure, request exception
  • migrate_users dry-run — no API calls made, per-user output printed, no-email skip, missing --source-api-key exits cleanly

Test plan

  • All 17 new unit tests pass: pytest tests/unit/test_migrate_users.py -v
  • cometx copy SOURCE DEST (workspace missing, no flag) → error with --create-workspaces suggestion
  • cometx copy SOURCE DEST --create-workspaces (workspace missing) → workspace created, copy proceeds
  • cometx migrate-users --api-key KEY --source-api-key KEY --dry-run → per-user preview, no API calls
  • cometx migrate-users --api-key KEY --chargeback-report /path/to/report.json → loads from file
  • cometx migrate-users --api-key KEY (no source key, no report) → clear error message

🤖 Generated with Claude Code


Generated description

Below is a concise technical summary of the changes proposed in this PR:

graph LR
migrate_users_("migrate_users"):::modified
resolve_server_url_("_resolve_server_url"):::added
add_member_("_add_member"):::modified
REQUESTS_("REQUESTS"):::added
create_workspace_("_create_workspace"):::modified
migrate_users_ -- "Adds URL resolution, enforces https, errors when undetermined." --> resolve_server_url_
migrate_users_ -- "Uses add_member_url, captures status/error, writes failures." --> add_member_
add_member_ -- "Now posts JSON body using requests' json parameter." --> REQUESTS_
create_workspace_ -- "Makes workspace creation reusable; propagates HTTP errors." --> REQUESTS_
classDef added stroke:#15AA7A
classDef removed stroke:#CD5270
classDef modified stroke:#EDAC4C
linkStyle default stroke:#CBD5E1,font-size:13px
Loading

Improve the migrate_users CLI by mandating explicit source API credentials when needed, resolving server URLs more robustly, exposing failure output paths, and documenting/testing the argument changes alongside better per-user dry-run feedback. Strengthen the workspace-creation flow in CopyManager so it reuses the migrate-users helper, logs detailed HTTP errors, and avoids misusing the API client’s server_url property.

TopicDetails
Migrate Users CLI Harden migrate_users CLI argument handling, payload processing, and dry-run reporting while documenting the new options and covering behaviors via unit tests.
Modified files (3)
  • README.md
  • cometx/cli/migrate_users.py
  • tests/unit/test_migrate_users.py
Latest Contributors(2)
UserCommitDate
doug@comet.comAdd-cometx-rename-dupl...February 02, 2026
doug.blank@gmail.comAdded-cometx-copy-from...December 04, 2025
Workspace Creation Refine CopyManager workspace creation to reuse _create_workspace and surface HTTP failures with proper URL handling.
Modified files (1)
  • cometx/cli/copy.py
Latest Contributors(2)
UserCommitDate
chasefortierFix-migration-of-asset...February 19, 2026
doug.blank@gmail.comFix-model-element-asse...February 13, 2026
This pull request is reviewed by Baz. Review like a pro on (Baz).

@dsblank dsblank force-pushed the chasefortier/migrate-workspaces-and-users branch from d609047 to 7cd5e4b Compare March 13, 2026 17:14
- copy.py: move `import requests` to top-level; use `self.api._get_url_server()`
  instead of broken `self.api.server_url`; split HTTPError vs RequestException
  handlers for precise error messages
- migrate_users.py: add --url/--source-url args for self-hosted instances;
  fix _resolve_server_url (base64 padding, error handling, explicit-URL priority);
  require --source-api-key explicitly instead of silently reusing COMET_API_KEY;
  warn when source and dest URL+key are identical; handle dict-list API response
  in _get_existing_workspaces; show per-user output in dry-run; add
  --failures-output flag; use json= kwarg in _add_member; fix docstring examples
- tests/unit/test_migrate_users.py: 17 new unit tests covering _resolve_server_url,
  _get_existing_workspaces, _add_member, and dry-run behaviour

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
@dsblank dsblank force-pushed the dsblank/fix-migrate-users-pr20 branch from b2a1e72 to 125a3e2 Compare March 13, 2026 17:25
- Fix duplicate migrate-users subparser registration in __init__.py
- Validate explicit URLs require https:// in _resolve_server_url (SSRF fix)
- Remove silent COMET_CLOUD_URL fallback; fail fast when URL cannot be determined
- Handle {"workspaceNames": [...]} dict response shape in _get_existing_workspaces
- Deduplicate workspace creation by reusing _create_workspace from migrate_users in copy.py
- Update tests to match new behavior (SystemExit instead of COMET_CLOUD_URL fallback, new dict response shapes)

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
@dsblank dsblank merged commit 5b6007b into chasefortier/migrate-workspaces-and-users Mar 25, 2026
1 check passed
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.

1 participant