forcedotcom / salesforcedx-vscode

Salesforce Extensions for VS Code
https://developer.salesforce.com/tools/vscode
BSD 3-Clause "New" or "Revised" License
954 stars 406 forks source link

Can't run "SFDX: Push" when the default SO is one that I didn't create #2738

Closed AllanOricil closed 1 year ago

AllanOricil commented 3 years ago

Summary

I have a friend's Scratch Org (SO) connected on my sfdx and when I set it as the default one VSCode does not show the Push Command. But when I switch back to one that I created the push command appears.

Steps To Reproduce:

  1. Connect a Scratch Org that you did not create
  2. Set it as the default scratch org for your project
  3. Ctrl+shift+p and search for the extension's sfdx push command and verify it is not there
  4. Change the default scratch org for one that you created
  5. Ctrl+shift+p and search again for the extension's sfdx push command and verify it is now showing up

Expected result

The vscode SFDX Push command should appear whenever you have a SO selected as the default and when you are inside an sfdx project.

Actual result

The Vscode SFDX Push command does not show for SO that the user did not create, even when it is authenticated and known by sfdx.

Additional information

VS Code Version:

SFDX CLI Version: sfdx-cli/7.78.1-5a65d9dd2f win32-x64 node-v12.18.3

OS and version: Windows 10

AnanyaJha commented 3 years ago

Hi @AllanOricil thanks for reporting this! How did you connect to your friend's scratch org? The org picker in VS Code will only display scratch orgs associated with your default dev hub. To use a scratch org you didn't create (and see the push/pull commands), you'll need to log into the dev hub associated with that scratch org and set that as your default dev hub. To authorize the new dev hub, use the org picker in the bottom toolbar. Let me know if you have any questions!

AllanOricil commented 3 years ago

Hi @AllanOricil thanks for reporting this! How did you connect to your friend's scratch org? The org picker in VS Code will only display scratch orgs associated with your default dev hub. To use a scratch org you didn't create (and see the push/pull commands), you'll need to log into the dev hub associated with that scratch org and set that as your default dev hub. To authorize the new dev hub, use the org picker in the bottom toolbar. Let me know if you have any questions!

I authorized her Scratch Org on my sfdx using the credentials she generated on her side. I noticed I can do a source push command without any problems using the cli. Is just the VSCode Extension that does not allow me to do so. Also, the extension shows her SO set as my default one, so the extension knows her Scratch Org. It is just that it can't perform the push command with it.

Vscode extension knows about her Scratch Org image

Scratch Org is connected but does not show as one of mine image

Couple of pushes I did through the sfdx cli to her Scratch Org image

I think you just need to enable all Scratch Orgs to use the Push Command extension and not just the ones I created. Maybe you are getting the list of SO from the ones created by the user and not all the SO available.

With her SO selected, the Push command from the extension does not show up image

With my SO selected, even if it is expired, I can do a Push Command. image

AnanyaJha commented 3 years ago

Hi @AllanOricil we tried to reproduce your issue by creating a scratch org, switching to a different dev hub (user), then setting the default org to the unrelated scratch org using the CLI, and we actually did see the Push and Pull commands in VS Code. Could you share the contents of your sfdx-config.json file when you're connected to your friend's scratch org? It looks like you're on the latest version of the CLI, could you also tell us which version of the Salesforce Extensions you're using?

AllanOricil commented 3 years ago

Hi @AllanOricil we tried to reproduce your issue by creating a scratch org, switching to a different dev hub (user), then setting the default org to the unrelated scratch org using the CLI, and we actually did see the Push and Pull commands in VS Code. Could you share the contents of your sfdx-config.json file when you're connected to your friend's scratch org? It looks like you're on the latest version of the CLI, could you also tell us which version of the Salesforce Extensions you're using?

OBS: All the pictures below are displaying the computer time to help you see that I'm doing the tests right.

@AnanyaJha In the picture below you can see my sfdx and vscode extension versions.

image

I just switched to her Scratch Org and the sfdx-config.json changed its content too. The Vscode extension also indicates this change in the button on the status bar (blue bar on the bottom).

image

But the Push command doesn't show up. image

Now I changed to my Expired Scratch Org, to show that when the Scratch Org is mine the command appears, even when the SO is expired. image

And I can see the Push command image

AnanyaJha commented 3 years ago

Thanks @AllanOricil! Can you also post the output to sfdx force:config:get defaultdevhubusername?

AllanOricil commented 3 years ago

Thanks @AllanOricil! Can you also post the output to sfdx force:config:get defaultdevhubusername?

@AnanyaJha dont consider that weird error message after updating sfdx cli. That will be another bug I will open haha I also took the opportunity to update my vscode extension to the latest and the error is still there.

image

AnanyaJha commented 3 years ago

Hi @AllanOricil we're still working on reproducing this issue- can you confirm how you logged into your friend's org? We tried the following process:

  1. I created a scratch org and created a scratch org user for my friend to use
  2. Went into the scratch org and changed the email address so she was able to generate a password for her scratch org user
  3. She changed the password and auth'd into the scratch org user with the custom login url that was generated when i created a scratch org user

After this process, she does not see the Push/Pull commands in VS Code nor the CLI. Is this the same process you used for your friend's scratch org? cc @sfsholden

AllanOricil commented 3 years ago

Hi @AllanOricil we're still working on reproducing this issue- can you confirm how you logged into your friend's org? We tried the following process:

  1. I created a scratch org and created a scratch org user for my friend to use
  2. Went into the scratch org and changed the email address so she was able to generate a password for her scratch org user
  3. She changed the password and auth'd into the scratch org user with the custom login url that was generated when i created a scratch org user

After this process, she does not see the Push/Pull commands in VS Code nor the CLI. Is this the same process you used for your friend's scratch org? cc @sfsholden

@AnanyaJha

My friend and I are using the same devhuborg. She is connected to this devhub with her user and I with mine. She created one Scratch Org, then generated the username and password using the CLI sfdx force:user:password:generate -u HER_SCRATCH_ORG_USERNAME Then she gave the password and username to me. From inside that sfdx project on the images I posted here, I ran sfdx force:auth:web:login but using the VSCode Extension Command, instead of typing the command. Vscode Opened the browser and I entered the credentials she gave to me. The authentication worked without a problem and her Scratch Org was now registered on my SFDX. I connected to her Scratch Org because I needed to push some code changes I did in that sfdx project. After connecting I tried to run the Vscode Extension Push Command and I noticed it was not showing up. Then I had to typesfdx force:source:push -u nina_so_2 -f on the terminal to push everything and it worked! And this was the moment I understood something weird was happening.

AllanOricil commented 3 years ago

@AnanyaJha I think I discovered the issue. Her scratch org was registered as a "nonScratchOrg". But as I told before, I can run sfdx force:source:push without any problem and It is a Scratch Org! Maybe the VScode Extension is using the list of "nonScratchOrgs" to determine if it should or not show the Push command, which in this case shown below would break this logic. What do you think?

Obs 1: I deleted some information in the output below for protection. Obs 2: I registered this SO using the VSCOde Extension Command.

image

AnanyaJha commented 3 years ago

Hi @AllanOricil thanks for all the info! We attempted to reproduce the issue by going through the same steps you mentioned above (creating two dev hub users & using the generated scratch org pwd to log in from the second dev hub user), but we are correctly seeing the Push/Pull commands in VS Code. It seems like the issue may be with the specific scratch org you're attempting to use. Which auth file is the screenshot from, where are you seeing the nonScratchOrgs section? We aren't using the nonScratchOrgs attribute when determining whether an org is scratch org; we check for the presence of a devhubUsername attribute in the auth info for the scratch org. If there is an associated devhubUsername, then it's a scratch org and the Push/Pull commands will be displayed. In the .sfdx folder in your home directory, open up the auth file associated with the scratch org you're working with. There should be a field for devhubUsername as such:

Screen Shot 2020-11-20 at 11 25 04 AM
AllanOricil commented 3 years ago

you

@AnanyaJha This is the content of that file you asked. I just changed the accessToken and refreshToken to use a random, non usable, code.

{
    "orgId": "00D3D0000003PlcUAE",
    "accessToken": "9a0511de65229e046fe77493276e553196c40d6a7a7c5e123d027b40775f4764c695400d8982b1a7b5fd7eb7a2f3ed:65015ddc94997cff9a602499d8da5bdd",
    "refreshToken": "555ff975fb1850dc6695d3f:ce46366f0d67d600493e17b2e8fa6053",
    "instanceUrl": "https://page-dream-9422-dev-ed.cs70.my.salesforce.com",
    "loginUrl": "https://test.salesforce.com/",
    "username": "test-eizjxrgpwekh@example.com",
    "clientId": "PlatformCLI",
    "isDevHub": false
}

You can confirm that the credentials above are for the right SO in the images below.

image

image

AnanyaJha commented 3 years ago

@AllanOricil Thanks! Can you try adding in this line to the auth file for the scratch org "devHubUsername": "yourdevhubusername"? When you authorize a new scratch org, the CLI should be adding in a devHubUsername field to indicate what dev hub the scratch org is associated with. Ideally, reauthorizing should fix the problem but we can try manually adding the needed data too.

AllanOricil commented 3 years ago

@AnanyaJha it worked. Here is what I did:

1st Test

1 - Manually added a REAL devhubusername to the devHubUsername prop in that file, as shown below:

{
    "orgId": "00D3D0000003PlcUAE",
    "accessToken": "9a0511de65229e046f3dad049d8da5bdd",
    "refreshToken": "555ff975fb1850dc6f96ece3cdfb020bc7695d3f:ce46366f0d67d600493e17b2e8fa6053",
    "instanceUrl": "https://page-dream-9422-dev-ed.cs70.my.salesforce.com",
    "loginUrl": "https://test.salesforce.com/",
    "username": "test-eizjxrgpwekh@example.com",
    "clientId": "PlatformCLI",
    "devHubUsername": "allan.oricil@hpe.com",
    "isDevHub": false
}

2 - After that I tried to find the push command and it was still not showing up 3 - Closed and Opened VSCode in the same Workspace and this time the command was appearing. This is probably because the files are read during the Activation of the extension. Maybe you can change it to read those files when they change in the .sfdx with a file listener. This way the user does not need to close and open the project again.

image

2nd Test

I also added a random string on the devHubUsername prop and the command also appeared. After editing the file with the random string I closed and opened VSCode again to make sure the changes were picked up. So this devhubusername seems to be just used to show the push command, and it actually can be anything. Does it make sense? Maybe there is another way to control this.

{
    "orgId": "00D3D0000003PlcUAE",
    "accessToken": "9a0511de65229e046f3dad049d8da5bdd",
    "refreshToken": "555ff975fb1850dc6f96ece3cdfb020bc7695d3f:ce46366f0d67d600493e17b2e8fa6053",
    "instanceUrl": "https://page-dream-9422-dev-ed.cs70.my.salesforce.com",
    "loginUrl": "https://test.salesforce.com/",
    "username": "test-eizjxrgpwekh@example.com",
    "clientId": "PlatformCLI",
    "devHubUsername": "blabla",
    "isDevHub": false
}
AllanOricil commented 3 years ago

I authorized a new Scratch Org created by my colleague using the VSCode Extension and the same problem happened again. The auth file inside ./sfdx does not have the devHubUsername again. Here is the Channel output showing the command vscode executed:

image

image

AnanyaJha commented 3 years ago

Hi @AllanOricil okay so it looks like the issue here is that the CLI does not reliably add the devhubusername attribute when you log in using a user on the dev hub and the generate password/key for the scratch org. I can log a new bug to look into whether the CLI should be adding in the devhubusername attribute in this scenario or whether there's a different attribute we can use to reliably detect a scratch org. As we discussed earlier, the workaround for now is to manually add in the devhubusername attribute. Thanks for reporting this!

git2gus[bot] commented 3 years ago

This issue has been linked to a new work item: W-8515293

AllanOricil commented 3 years ago

Hi @AllanOricil okay so it looks like the issue here is that the CLI does not reliably add the devhubusername attribute when you log in using a user on the dev hub and the generate password/key for the scratch org. I can log a new bug to look into whether the CLI should be adding in the devhubusername attribute in this scenario or whether there's a different attribute we can use to reliably detect a scratch org. As we discussed earlier, the workaround for now is to manually add in the devhubusername attribute. Thanks for reporting this!

@AnanyaJha Thank you for your response

dcstuff commented 2 years ago

This bug should be a top priority only because I hit it today and it's a minor inconvenience!

  1. Authorize to an org, use credentials of someone else's scratch org. Rare use case, sure, but it happens!
  2. SFDX: Push blah blah command not there

sfdx force:source:push works as expected.