Scratch org creation omits the namespace spec in the sfdx-project and project-scratch-def files

Issue #1363 resolved
Jeff May created an issue

When creating a scratch org (DX connection) in a project with a namespace specified, the resulting scratch org is missing the namespace attribute.

It is easy enough to manually add the line to the scratch org json file, but this used to be automatic in versions prior to 2.0.7.0

Comments (12)

  1. Scott Wells repo owner

    Hmmm...that's strange. I'm not aware of anything I might have done to regress this, but obviously I did. I'll take a look today and see if I can figure out what's going on. I'll have a new release out in the next few days, so hopefully I can take care of it in that one. Thanks for bringing this to my attention, and sorry for the issue.

  2. Scott Wells repo owner

    That's correct, Jeff. 2.0.7.1 and 2.0.7.2 have been updates to address issues with JetBrains' 2019.2 IDEs. Once I have that all squared away I'll get a bug fix release out including this. Sorry for the delay!

  3. Scott Wells repo owner

    Hi, Jeff. I'm finally getting to take a look at this. Can you explain the workflow that used to work but no longer does? I just want to make sure I understand the nature of the regression so that I'm debugging the right thing.

  4. Jeff May reporter

    If I have a DX project, and add “namespace” : “jmay” to the project-scratch-def.json. Then, when I create a new scratch org, the new scratch org json file is missing the namespace.

  5. Scott Wells repo owner

    Sorry, Jeff. I still think I'm missing something. I didn't think you could specify a namespace in project-scratch-def.json, only in sfdx-project.json. To be thorough I just tried to create an org with "namespace": "<my-namespace>" in the project-scratch-def.json and force:org:create failed with a syntax error. I then updated my sfdx-project.json with that same entry and created a scratch org against the dev hub where <my-namespace> is registered, and it created a scratch org with that namespace. Can you please explain what you're doing differently?

  6. Jeff May reporter

    No problem at all. Here are the steps I take that repro the issue (I am on IC 2.0.8.3 now)

    1. Open a DX project

    1a) sfdx-project.json

    {
    "packageDirectories": [
    {
    "path": "force-app",
    "default": true
    }
    ],
    "namespace": "XXXX",
    "sfdcLoginUrl": "https://login.salesforce.com",
    "sourceApiVersion": "45.0"
    }

    1b) project-scratch-def.json

    {
    "orgName": "XXXX Place",
    "edition": "Developer",
    "features": [],
    "namespace": "XXXX",
    "settings": {
    "orgPreferenceSettings": {
    "s1DesktopEnabled": true
    }
    }
    }

    1. Click Manage Connections
    2. Click DX (to create scratch org)
    3. Select the DevHub with the namespace
    4. Enter Org name (jtest)
    5. Click OK
    6. Yes, I wish to save
    7. Confirm the scratch org file name
    8. look at jtest-scratch-def.json and no namespace entry

    {
    "orgName": "jest",
    "edition": "Developer",
    "features": [],
    "orgPreferences": {
    "enabled": [],
    "disabled": []
    }
    }

    1. Manually edit the jtest-scratch-def.json add the line

    "namespace": "XXXX",

    so the result is

    {
    "orgName": "jest",
    "edition": "Developer",
    "namespace": "XXXX",
    "features": [],
    "orgPreferences": {
    "enabled": [],
    "disabled": []
    }
    }

    1. Open the connection and see the namespace is being used

    #####

  7. Scott Wells repo owner

    Thanks, Jeff. I don't think that *-scratch-def.json supports the namespace attribute:

    https://developer.salesforce.com/docs/atlas.en-us.sfdx_dev.meta/sfdx_dev/sfdx_dev_scratch_orgs_def_file.htm

    That's why it's being lost as it's "laundered" through IC. IC deserializes what you have in your JSON file into an in-memory object which doesn't have a namespace property, then when you tell IC to save that back as a file, the property has been stripped.

    The force:org:create command derives its namespace from the sfdx-project.json in the working directory:

    https://developer.salesforce.com/docs/atlas.en-us.sfdx_dev.meta/sfdx_dev/sfdx_dev_ws_config.htm

    Of course, as you point out, you also need to be working against a dev hub for which that namespace has been registered.

    I think this is working properly if not exactly as expected. It could also be that I'm missing something here, but based on my understanding the issue is that adding the namespace in 1b isn't supported. If you tried to use sfdx force:org:create against the file from 1b directly it would fail with a syntax error.

  8. Jeff May reporter

    Thanks, Scott. All better.

    I removed the namespace attribute from the *-scratch-def.json and left it in the sfdx-project.json. Created a new scratch org and it got namespaced.

    Closing this issue now.

  9. Log in to comment