Skip to content

feat: add copy_and_replace_credentials convenience method to FlowsResource#15

Merged
saksham-nexla merged 2 commits intomainfrom
devin/1772826018-copy-replace-credentials
Mar 7, 2026
Merged

feat: add copy_and_replace_credentials convenience method to FlowsResource#15
saksham-nexla merged 2 commits intomainfrom
devin/1772826018-copy-replace-credentials

Conversation

@devin-ai-integration
Copy link
Copy Markdown
Contributor

@devin-ai-integration devin-ai-integration Bot commented Mar 6, 2026

feat: add copy_and_replace_credentials convenience method to FlowsResource

Summary

Adds a new convenience method FlowsResource.copy_and_replace_credentials() that copies a flow and replaces credentials on specified resources in a single call.

The method accepts a resource_credential_mapping: Dict[int, int] where keys are original source/sink IDs and values are the new credential IDs to assign. Internally it:

  1. Copies the flow with reuse_data_credentials=True (so copied resources keep their original creds)
  2. Iterates through data_sources and data_sinks in the copy response, matching via copied_from_id
  3. Calls sources.update() / destinations.update() for each matched resource
  4. Optionally adds the copied flow to a target project via client.projects.add_flows()
  5. Re-fetches and returns the updated flow

Resources not in the mapping are left untouched. The reuse_data_credentials flag is always forced True regardless of user-supplied copy_options.

Six unit tests cover: full source+sink replacement, partial mapping (unmapped sinks left alone), copy option preservation, empty mapping (pure copy, no updates), target project assignment, and no-project default behavior.

Updates since last revision

  • Added optional target_project_id: Optional[int] = None parameter to copy_and_replace_credentials().
  • When target_project_id is set, the method calls self.client.projects.add_flows(target_project_id, ProjectFlowList(flows=[origin_node_id])) after credential replacement to move the copied flow into the specified project.
  • Added ProjectFlowList import from nexla_sdk.models.projects.requests.
  • Two new unit tests: test_copy_and_replace_credentials_with_target_project and test_copy_and_replace_credentials_no_target_project.

Review & Testing Checklist for Human

  • Verify copied_from_id is reliably populated by the real API on flow copy responses. The method silently skips resources where copied_from_id is None — if the API doesn't always set this field, credential replacement will silently not happen. This is the highest-risk assumption and is not verifiable from unit tests alone.
  • Consider partial failure behavior. If the copy succeeds but a credential update or add_flows call fails, the copied flow exists in an intermediate state (some credentials updated, possibly not in target project). There is no rollback. Decide if this is acceptable or if error handling/documentation should be added.
  • copied_flow.flows[0] index access on line 263 — will raise IndexError if the copy response returns an empty flows list. Unlikely in practice, but unguarded. Note this is now reached unconditionally (moved before the target_project_id check) so it affects all calls, not just project-move calls.
  • Verify origin_node_id is the correct identifier for ProjectFlowList.flows. The method passes origin_node_id to add_flows() — confirm this matches what the admin API expects for adding flows to a project.
  • Integration test recommended. Run against a real Nexla environment: copy a flow with known source/sink IDs, credential IDs, and a target project ID. Verify the returned flow has the expected credentials and belongs to the target project.

Notes

…ource

Adds a new method that copies a flow and replaces credentials on
specified resources in a single call. The mapping uses original
resource IDs (source/sink) as keys and new credential IDs as values.

Resources not in the mapping keep their original credentials.

Co-Authored-By: abhijit.bharadwaj <abhijit.bharadwaj@nexla.com>
@devin-ai-integration
Copy link
Copy Markdown
Contributor Author

Prompt hidden (unlisted session)

@devin-ai-integration
Copy link
Copy Markdown
Contributor Author

🤖 Devin AI Engineer

I'll be helping with this pull request! Here's what you should know:

✅ I will automatically:

  • Address comments on this PR. Add '(aside)' to your comment to have me ignore it.
  • Look at CI failures and help fix them

Note: I can only respond to comments from users who have write access to this repository.

⚙️ Control Options:

  • Disable automatic comment and CI monitoring

@saksham-nexla
Copy link
Copy Markdown
Member

Code review

No issues found. Checked for bugs and CLAUDE.md compliance.

🤖 Generated with Claude Code

- If this code review was useful, please react with 👍. Otherwise, react with 👎.

Co-Authored-By: abhijit.bharadwaj <abhijit.bharadwaj@nexla.com>
@saksham-nexla saksham-nexla merged commit 8358d14 into main Mar 7, 2026
6 of 7 checks passed
saksham-nexla added a commit that referenced this pull request Mar 22, 2026
Merges 3 PRs from main:
- #13: Make DataMapInfo.description and NotificationSetting.resource_id optional
- #14: Add monitoring endpoint methods with explicit params for MCP integration
- #15: Add copy_and_replace_credentials convenience method to FlowsResource

Resolved conflicts in base_resource.py, metrics.py, organizations.py,
and users.py by keeping branch's additional methods while incorporating
main's enhanced audit_log params and new monitoring methods.
saksham-nexla added a commit that referenced this pull request Mar 22, 2026
Add 36 new tests (29 Python, 7 TypeScript) covering methods from
merged PRs #13, #14, #15 and their TS SDK mirrors:

Python:
- base_resource get_audit_log filter/pagination params (6 tests)
- metrics publish_raw, resource_flow_metrics, flow_metrics_summary (4)
- organizations audit_log explicit params, flow_status_metrics (5)
- users audit_log params, account_metrics aggregate, flow_status_metrics (6)
- flows get_flow_logs, search_flow_logs, active_flows_metrics, run_status (8)

TypeScript:
- flows copy_and_replace_credentials edge cases (3)
- organizations/users audit_log query params and empty responses (4)
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