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 Version 7.151.1 force:mdapi:deploy cannot fails when attempting to deploy metadata without apex classes #1542

Closed
bast-shb opened this issue May 23, 2022 · 9 comments
Labels
bug Issue or pull request that identifies or fixes a bug investigating We're actively investigating this issue

Comments

@bast-shb
Copy link

Summary

Hi. We use sfdx force:mdapi:deploy to deploy metadata to our org. We have specifically decided to omit the --testlevel flag, as it is very convenient that the cli chooses the testlevel based on the metadata (for apex classes and such, it is RunLocalTests, while NoTestRun is selected when there are no apex classes or similar (see https://developer.salesforce.com/docs/atlas.en-us.api_meta.meta/api_meta/meta_deploy_running_tests.htm for reference on when each is choosen).

However, today when trying to deploy with Version 7.151.1, we received the error sf:INVALID_OPERATION: INVALID_OPERATION: testLevel of NoTestRun cannot be used in production organizations. We tried revering to version 7.150.0 but got the same result. Revering back to 7.145.0, however, resulted in the expected scenario: The deployment was successful.

Thus, the error reported here is that in at least versions 7.150.0-7.151.0, a wrongful error is thrown when attempting to deploy metadata with NoTestRun, when the metadata does not contain any apex classes or similar that requires unit tests.

Steps To Reproduce:

  1. Create an sfdx project with metadata, such a fields for account, but no apex classes or other code.
  2. run sfdx force:mdapi:deploy towards a production org, without specifying the --testlevel flag.

Expected result

The metadata deployment is allowed and successful.

Actual result

The error sf:INVALID_OPERATION: INVALID_OPERATION: testLevel of NoTestRun cannot be used in production organizations is thrown.

System Information

I cannot supply this as the error was received on our cloud agents used for builds and deployments. The agent simply runs npm install sfdx-cli --global at the start of the run, to get the latest version of the cli.

Additional information

image

@bast-shb bast-shb added the investigating We're actively investigating this issue label May 23, 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.

@alan-morey
Copy link

Also experiencing the same error.

I have a metadata format package folder as follows:

$ tree build/src-package && echo && find build/src-package -type f -print -exec cat {} \; -exec echo -e "\n---\n" \;
build/src-package                                                                                                                                                                         
├── destructiveChangesPost.xml                                                                                                                                                            
├── destructiveChangesPre.xml                                                                                                                                                             
├── package.xml                                                                                                                                                                           
└── permissionsets                                                                                                                                                                        
    └── AlanTest.permissionset                                                                                                                                                            

1 directory, 4 files
                                                                                                                                                                                          
build/src-package/destructiveChangesPost.xml                                                                                                                                              
<?xml version="1.0" encoding="UTF-8"?>                                                                                                                                                    
<Package xmlns="http://soap.sforce.com/2006/04/metadata">

</Package>                                                                                                                                                                                
---                                                                                                                                                                                       

build/src-package/package.xml                                                                                                                                                             
<?xml version="1.0" encoding="UTF-8"?>                                                                                                                                                    
<Package xmlns="http://soap.sforce.com/2006/04/metadata">                                                                                                                                 
  <types>                                                                                                                                                                                 
    <members>AlanTest</members>
    <name>PermissionSet</name>
  </types>
  <version>52.0</version>
</Package>

---

build/src-package/destructiveChangesPre.xml                                                                                                                                               
<?xml version="1.0" encoding="UTF-8"?>                                                                                                                                                    
<Package xmlns="http://soap.sforce.com/2006/04/metadata">                                                                                                                                 
                                                                                                                                                                                          
</Package>                                                                                                                                                                                
---

build/src-package/permissionsets/AlanTest.permissionset                                                                                                                                   
<?xml version="1.0" encoding="UTF-8"?>                                                                                                                                                    
<PermissionSet xmlns="http://soap.sforce.com/2006/04/metadata">
    <description>Alan testing deployment errors in production. This should be deleted after testing is complete.</description>
    <hasActivationRequired>false</hasActivationRequired>
    <label>AlanTest</label>
    <license>Salesforce</license>
</PermissionSet>

---

Executing the following command to deploy:

$ sfdx force:mdapi:deploy -u PROD -d build/src-package -w -1
ERROR running force:mdapi:deploy:  INVALID_OPERATION: testLevel of NoTestRun cannot be used in production organizations

I have tested this deployment with the following sfdx versions:

  • 7.153.1 - ❌
  • 7.152.0 - ❌
  • 7.151.1 - ❌
  • 7.150.0 - ❌
  • 7.149.1 - ✔️

While not exhaustive, it appears that the issue was introduced with v7.150.0 which coincides with the promotion of force:mdapi:beta commands to force:mdapi.

force:mdapi:deploy command works as expected with v7.149.1.

Using force:mdapi:legacy:deploy with v7.153.1 also works as expected.

$ sfdx version && sfdx force:mdapi:legacy:deploy -u PROD -d build/src-package -w -1
sfdx-cli/7.153.1 linux-x64 node-v14.19.3                                                                                                                                                  
*** Deploying with SOAP ***                                                                                                                                                               
Job ID | 0Af5Y00000FPoLESA1                                                                                                                                                               
MDAPI PROGRESS | ████████████████████████████████████████ | 1/1 Components        

@WillieRuemmele
Copy link
Member

Hi @alan-morey

first off, wow, thank you for all of that research and investigating 👏 👏 . We've been working on getting a prod org to use to replicate this issue, but just from comparing the current vs the legacy commands, I can see that the default value for --testlevel was set to NoTestRun in the new version and was left undefined in the legacy version

If you're up for it, could you try modifying your local file and remove that default value? That might help us speed up the process and verify the fix at the same time. Depending on OS and install type (npm vs installer) you should be able to run which sfdx or npm root -g to find the installed location, from there navigate to node_modules/@salesforce/plugin-source/lib/commands/force/mdapi and remove line 129 of deploy.js?

@alan-morey
Copy link

Hi @WillieRuemmele,

I made the change as you suggested and removed line 129 from node_modules/@salesforce/plugin-source/lib/commands/force/mdapi/deploy.js, however that results in the following error:

sfdx version && sfdx force:mdapi:deploy -u PROD -d build/src-package -w -1
sfdx-cli/7.153.1 linux-x64 node-v14.19.3
ERROR running force:mdapi:deploy:  'undefined' is not a valid value for the enum 'TestLevel'

I then tried setting the default to an empty string:

        default: '',

However, that also results in error:

sfdx version && sfdx force:mdapi:deploy -u PROD -d build/src-package -w -1
sfdx-cli/7.153.1 linux-x64 node-v14.19.3
ERROR running force:mdapi:deploy:  '' is not a valid value for the enum 'TestLevel'

Also tried setting default to null, similar error

@WillieRuemmele WillieRuemmele added the bug Issue or pull request that identifies or fixes a bug label Jun 9, 2022
@WillieRuemmele
Copy link
Member

Hi @alan-morey thank you so much for making those changes, and I apologize for the delay getting back to you.

Could you try one more thing for me? Could you remove lines 58-59 of that same file?

                runTests: this.getFlag('runtests'),
                testLevel: this.getFlag('testlevel'),

I've done some research, and testing between the mdapi:deploy and mdapi:legacy:deploy and now believe that if those keys are present, and set to undefined - what you tried, or NoTestLevel the default flag, it will fail. I'm hoping that by excluding those keys, it'll work correctly.

Just as a reminder: if you remove those, and the deploy succeeds - you will be deploying to prod

@alan-morey
Copy link

Hi @WillieRuemmele,

I removed those 2 lines and deployment request goes through:

$ sfdx version && sfdx force:mdapi:deploy -u PROD -d . -w -1 --checkonly
sfdx-cli/7.153.1 linux-x64 node-v14.19.3
Deploy ID: 0Af5Y00000FPuh1SAD
*** Deploying with SOAP ***
DEPLOY PROGRESS | ████████████████████████████████████████ | 1/1 Components

@WillieRuemmele
Copy link
Member

Hey @alan-morey 🎉 great news! we'll get this fixed right away! 😎

Thank you so much for all of your help

@ganesh2109-cloud
Copy link

@WillieRuemmele Facing the same issue, any idea which version of the sfdx-cli will the fix be a part of?

@WillieRuemmele
Copy link
Member

Hi @ganesh2109-cloud I'm planning on getting those changes into this week's latest-rc build, it should be available as a standalone install before that. I'll update this thread when it's available

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Issue or pull request that identifies or fixes a bug investigating We're actively investigating this issue
Projects
None yet
Development

No branches or pull requests

5 participants