Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

SFDX force:org:clone Errors if there is a sandbox that's been deleted and the name reused #1749

Closed
paulknebulaconsulting opened this issue Oct 12, 2022 · 6 comments
Labels
investigating We're actively investigating this issue

Comments

@paulknebulaconsulting
Copy link

Summary

When trying to clone a sandbox using a source sandbox, an error is returned when the source sandbox name has been reused, but the deleted sandbox is stuck in a 'Deleting' state, but is definitely not listed in the sandboxes list in Production.

ERROR running force:org:clone: The query returned more than 1 record

Steps To Reproduce:

  1. Create Developer Pro sandbox in production, using production as the source.
  2. Delete this sandbox (after you are allowed to).
  3. Create another sandbox with the same name as the first sandbox above once you are allowed to (it will block you while the SB is removed).
  4. Run: sfdx force:org:clone --type sandbox SandboxName=clonetest -u production@credentials -w 60 -a sb-clonetest -f config\feature-sandbox.json

feature-sandbox.json
{ "sourceSandboxName": "staging", "apexClassId" : "01p25000007eAbrAAE", "autoActivate" : true }

Expected result

Sandbox is cloned.

Actual result

Error is returned:
ERROR running force:org:clone: The query returned more than 1 record

System Information

  • Which shell/terminal are you using? Windows 11 / Powershell 7.2.6

{
"cliVersion": "sfdx-cli/7.171.0",
"architecture": "win32-x64",
"nodeVersion": "node-v16.17.0",
"pluginVersions": [
"@dx-cli-toolbox/sfdx-toolbox-package-utils 0.8.3 (user)",
"@oclif/plugin-autocomplete 1.3.0 (core)",
"@oclif/plugin-commands 2.2.0 (core)",
"@oclif/plugin-help 5.1.12 (core)",
"@oclif/plugin-not-found 2.3.1 (core)",
"@oclif/plugin-plugins 2.1.0 (core)",
"@oclif/plugin-update 3.0.0 (core)",
"@oclif/plugin-version 1.1.2 (core)",
"@oclif/plugin-warn-if-update-available 2.0.4 (core)",
"@oclif/plugin-which 2.1.0 (core)",
"alias 2.1.3 (core)",
"apex 1.2.0 (core)",
"auth 2.2.10 (core)",
"community 2.0.3 (core)",
"config 1.4.21 (core)",
"custom-metadata 2.0.1 (core)",
"data 2.1.4 (core)",
"generator 2.0.2 (core)",
"info 2.1.6 (core)",
"limits 2.0.3 (core)",
"org 2.2.7 (core)",
"packaging 1.9.4 (user)",
"schema 2.1.8 (core)",
"signups 1.2.4 (core)",
"source 2.0.16 (core)",
"telemetry 2.0.2 (core)",
"templates 55.1.0 (core)",
"trust 2.0.4 (core)",
"user 2.1.7 (core)",
"@salesforce/sfdx-plugin-lwc-test 1.0.1 (core)",
"salesforce-alm 54.8.1 (core)"
],
"osVersion": "Windows_NT 10.0.22621",
"shell": "cmd.exe",
"rootPath": "C:\Users\Paul Kissick\AppData\Local\sfdx\client\7.171.0-fbe9e7d"
}

Additional information

Looking at the log file after adding trace logging, there's a query to the tooling api:
SELECT Id, Status, SandboxName, SandboxInfoId, LicenseType, CreatedDate, CopyProgress, SandboxOrganization, SourceId, Description, EndDate FROM SandboxProcess WHERE SandboxName='staging' AND Status != 'D'

This shows there are 2 sandboxes, one in 'Deleting' status, one in 'Completed' status.
Screenshot 2022-10-12 151700

@paulknebulaconsulting paulknebulaconsulting added the investigating We're actively investigating this issue label Oct 12, 2022
@github-actions
Copy link

Thank you for filing this issue. We appreciate your feedback and will review the issue as soon as possible. Remember, however, that GitHub isn't a mechanism for receiving support under any agreement or SLA. If you require immediate assistance, contact Salesforce Customer Support.

@mkhokhlov
Copy link

mkhokhlov commented Oct 17, 2022

Getting the same error message with 7.172.0 when using the force:org:status command to check on a sandbox refresh status.

It definitely works fine in 7.146.1. The earliest version I tried in between was 7.162.0 and it fails with the same error message.

@paulknebulaconsulting
Copy link
Author

This looks to be related to this known issue:
https://trailblazer.salesforce.com/issues_view?id=a1p4V0000033rTMQAY&title=source-sandbox-of-clones-unable-to-be-refreshed-in-winter-23

@mkhokhlov
Copy link

mkhokhlov commented Oct 27, 2022

The fact that it works just fine with sfdx-cli 7.146.1 makes me think it has little to do with the platform. I dug the differences in sfdx-core/org/org.ts in 7.146.1 and 7.173.0 and the former seems more resilient. IIUC, it uses the new sandbox instance ID when querying SandboxProcess.

I couldn't figure out when exactly things went side ways, but I found an interesting bit in forcedotcom/sfdx-core#571: it added queryLatestSandboxProcessBySandboxName(string) to sfdx-core/src/org/org.ts, and its query prevents duplicates by having ORDER BY CreatedDate DESC LIMIT 1 clauses.

Can we add the same clauses to the query used in querySandboxProcess(string), so that it's more resilient? It is called from querySandboxProcessBySandboxInfoId(string), which is called from pollStatusAndAuth().

@mkhokhlov
Copy link

@mshanemc any thoughts on the comment above?

@mpaul1
Copy link

mpaul1 commented Nov 29, 2022

version 7.171 was working, but stopped today. I get the same error for each version up to the current 7.178
version 7.152 works properly

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
investigating We're actively investigating this issue
Projects
None yet
Development

No branches or pull requests

3 participants