Repository: pypa/pipenv

Issue:
Should `pipenv lock` be generating a marker of `null` when `extras` used?
### Issue description

A `Pipfile.lock` is being generated with a `marker` of `null`. When being passed to other tools to parse that lockfile, such as `pipfile2req` its erroring on that entry. I took a quick look at PEP 508 and it didn't say anything about a `marker` of `null` but did suggest it should only be a string.

### Expected result

I'm guessing, if the result is `null` just don't include markers.

### Actual result

When possible, provide the verbose output (`--verbose`), especially for locking and dependencies resolving issues.

### Steps to replicate

```
➜  test git:(main) ✗ cat Pipfile
[[source]]
url = "https://pypi.org/simple"
verify_ssl = true
name = "pypi"

[packages]
pydantic = "==1.10.2"
email-validator = "==1.3.0"
```

```
➜  test git:(main) ✗ pipenv lock
Locking [packages] dependencies...
Building requirements...
Resolving dependencies...
✔ Success!
Locking [dev-packages] dependencies...
Updated Pipfile.lock (d5f483e04b72426b3574dfadf29d845164fc106b68e966b5d0bf515817ff3cec)!
```

```
"pydantic": {
  ...snipped
            ],
            "index": "pypi",
            "version": "==1.10.2"
        },
```

Looks great. Now let's specify `{extras}`

```
[[source]]
url = "https://pypi.org/simple"
verify_ssl = true
name = "pypi"

[packages]
pydantic = {extras = ["email"],version = "==1.10.2"}
```

```
➜  test git:(main) ✗ pipenv lock
Locking [packages] dependencies...
Building requirements...
Resolving dependencies...
✔ Success!
Locking [dev-packages] dependencies...
Updated Pipfile.lock (b7af3ff13b8fd9cd4e13a037c9d0a95bdad213656719e0e6d330e0ab5d8b93b7)!
```

```
"pydantic": {
            "extras": [
                "email"
            ],
            "hashes": [
... snipped
            ],
            "index": "pypi",
            "markers": null,
            "version": "==1.10.2"
        },
```

We now have a `markers` `null` in the output.


---

<details><summary>$ pipenv --support</summary>

Pipenv version: `'2022.11.11'`

Pipenv location: `'/Users/andy/Library/Python/3.9/lib/python/site-packages/pipenv'`

Python location: `'/Library/Developer/CommandLineTools/usr/bin/python3'`

OS Name: `'posix'`

User pip version: `'22.3'`

user Python installations found:

  - `3.9.6`: `/usr/bin/python3`

PEP 508 Information:

```
{'implementation_name': 'cpython',
 'implementation_version': '3.9.6',
 'os_name': 'posix',
 'platform_machine': 'arm64',
 'platform_python_implementation': 'CPython',
 'platform_release': '21.6.0',
 'platform_system': 'Darwin',
 'platform_version': 'Darwin Kernel Version 21.6.0: Mon Aug 22 20:19:52 PDT '
                     '2022; root:xnu-8020.140.49~2/RELEASE_ARM64_T6000',
 'python_full_version': '3.9.6',
 'python_version': '3.9',
 'sys_platform': 'darwin'}
```

System environment variables:

  - `TERM_SESSION_ID`
  - `SSH_AUTH_SOCK`
  - `LC_TERMINAL_VERSION`
  - `COLORFGBG`
  - `ITERM_PROFILE`
  - `XPC_FLAGS`
  - `LANG`
  - `PWD`
  - `SHELL`
  - `__CFBundleIdentifier`
  - `TERM_PROGRAM_VERSION`
  - `TERM_PROGRAM`
  - `PATH`
  - `LC_TERMINAL`
  - `COLORTERM`
  - `COMMAND_MODE`
  - `TERM`
  - `HOME`
  - `TMPDIR`
  - `USER`
  - `XPC_SERVICE_NAME`
  - `LOGNAME`
  - `ITERM_SESSION_ID`
  - `__CF_USER_TEXT_ENCODING`
  - `SHLVL`
  - `OLDPWD`
  - `HOMEBREW_PREFIX`
  - `HOMEBREW_CELLAR`
  - `HOMEBREW_REPOSITORY`
  - `MANPATH`
  - `INFOPATH`
  - `ZSH`
  - `PAGER`
  - `LESS`
  - `LSCOLORS`
  - `GITHUB_TOKEN`
  - `VERCEL_TOKEN`
  - `PNPM_HOME`
  - `NVM_DIR`
  - `NVM_CD_FLAGS`
  - `NVM_BIN`
  - `NVM_INC`
  - `_`
  - `PIP_DISABLE_PIP_VERSION_CHECK`
  - `PIP_PYTHON_PATH`
  - `PYTHONDONTWRITEBYTECODE`
  - `PYTHONFINDER_IGNORE_UNSUPPORTED`

Pipenv–specific environment variables:


Debug–specific environment variables:

  - `PATH`: `/Users/andy/.nvm/versions/node/v19.1.0/bin:/Users/andy/Library/Python/3.9/bin:/Users/andy/Library/pnpm:/opt/homebrew/bin:/opt/homebrew/sbin:/usr/local/bin:/usr/bin:/bin:/usr/sbin:/sbin`
  - `SHELL`: `/bin/zsh`
  - `LANG`: `en_CA.UTF-8`
  - `PWD`: `/Users/andy/c/pipenv/test`


---------------------------

Contents of `Pipfile` ('/Users/andy/c/pipenv/test/Pipfile'):

```toml
[[source]]
url = "https://pypi.org/simple"
verify_ssl = true
name = "pypi"

[packages]
pydantic = "==1.10.2"
email-validator = "==1.3.0"

```


Contents of `Pipfile.lock` ('/Users/andy/c/pipenv/test/Pipfile.lock'):

```json
{
    "_meta": {
        "hash": {
            "sha256": "d5f483e04b72426b3574dfadf29d845164fc106b68e966b5d0bf515817ff3cec"
        },
        "pipfile-spec": 6,
        "requires": {},
        "sources": [
            {
                "name": "pypi",
                "url": "https://pypi.org/simple",
                "verify_ssl": true
            }
        ]
    },
    "default": {
        "dnspython": {
            "hashes": [
                "sha256:0f7569a4a6ff151958b64304071d370daa3243d15941a7beedf0c9fe5105603e",
                "sha256:a851e51367fb93e9e1361732c1d60dab63eff98712e503ea7d92e6eccb109b4f"
            ],
            "markers": "python_version >= '3.6' and python_version < '4.0'",
            "version": "==2.2.1"
        },
        "email-validator": {
            "hashes": [
                "sha256:553a66f8be2ec2dea641ae1d3f29017ab89e9d603d4a25cdaac39eefa283d769",
                "sha256:816073f2a7cffef786b29928f58ec16cdac42710a53bb18aa94317e3e145ec5c"
            ],
            "index": "pypi",
            "version": "==1.3.0"
        },
        "idna": {
            "hashes": [
                "sha256:814f528e8dead7d329833b91c5faa87d60bf71824cd12a7530b5526063d02cb4",
                "sha256:90b77e79eaa3eba6de819a0c442c0b4ceefc341a7a2ab77d7562bf49f425c5c2"
            ],
            "markers": "python_version >= '3.5'",
            "version": "==3.4"
        },
        "pydantic": {
            "hashes": [
                "sha256:05e00dbebbe810b33c7a7362f231893183bcc4251f3f2ff991c31d5c08240c42",
                "sha256:06094d18dd5e6f2bbf93efa54991c3240964bb663b87729ac340eb5014310624",
                "sha256:0b959f4d8211fc964772b595ebb25f7652da3f22322c007b6fed26846a40685e",
                "sha256:19b3b9ccf97af2b7519c42032441a891a5e05c68368f40865a90eb88833c2559",
                "sha256:1b6ee725bd6e83ec78b1aa32c5b1fa67a3a65badddde3976bca5fe4568f27709",
                "sha256:1ee433e274268a4b0c8fde7ad9d58ecba12b069a033ecc4645bb6303c062d2e9",
                "sha256:216f3bcbf19c726b1cc22b099dd409aa371f55c08800bcea4c44c8f74b73478d",
                "sha256:2d0567e60eb01bccda3a4df01df677adf6b437958d35c12a3ac3e0f078b0ee52",
                "sha256:2e05aed07fa02231dbf03d0adb1be1d79cabb09025dd45aa094aa8b4e7b9dcda",
                "sha256:352aedb1d71b8b0736c6d56ad2bd34c6982720644b0624462059ab29bd6e5912",
                "sha256:355639d9afc76bcb9b0c3000ddcd08472ae75318a6eb67a15866b87e2efa168c",
                "sha256:37c90345ec7dd2f1bcef82ce49b6235b40f282b94d3eec47e801baf864d15525",
                "sha256:4b8795290deaae348c4eba0cebb196e1c6b98bdbe7f50b2d0d9a4a99716342fe",
                "sha256:5760e164b807a48a8f25f8aa1a6d857e6ce62e7ec83ea5d5c5a802eac81bad41",
                "sha256:6eb843dcc411b6a2237a694f5e1d649fc66c6064d02b204a7e9d194dff81eb4b",
                "sha256:7b5ba54d026c2bd2cb769d3468885f23f43710f651688e91f5fb1edcf0ee9283",
                "sha256:7c2abc4393dea97a4ccbb4ec7d8658d4e22c4765b7b9b9445588f16c71ad9965",
                "sha256:81a7b66c3f499108b448f3f004801fcd7d7165fb4200acb03f1c2402da73ce4c",
                "sha256:91b8e218852ef6007c2b98cd861601c6a09f1aa32bbbb74fab5b1c33d4a1e410",
                "sha256:9300fcbebf85f6339a02c6994b2eb3ff1b9c8c14f502058b5bf349d42447dcf5",
                "sha256:9cabf4a7f05a776e7793e72793cd92cc865ea0e83a819f9ae4ecccb1b8aa6116",
                "sha256:a1f5a63a6dfe19d719b1b6e6106561869d2efaca6167f84f5ab9347887d78b98",
                "sha256:a4c805731c33a8db4b6ace45ce440c4ef5336e712508b4d9e1aafa617dc9907f",
                "sha256:ae544c47bec47a86bc7d350f965d8b15540e27e5aa4f55170ac6a75e5f73b644",
                "sha256:b97890e56a694486f772d36efd2ba31612739bc6f3caeee50e9e7e3ebd2fdd13",
                "sha256:bb6ad4489af1bac6955d38ebcb95079a836af31e4c4f74aba1ca05bb9f6027bd",
                "sha256:bedf309630209e78582ffacda64a21f96f3ed2e51fbf3962d4d488e503420254",
                "sha256:c1ba1afb396148bbc70e9eaa8c06c1716fdddabaf86e7027c5988bae2a829ab6",
                "sha256:c33602f93bfb67779f9c507e4d69451664524389546bacfe1bee13cae6dc7488",
                "sha256:c4aac8e7103bf598373208f6299fa9a5cfd1fc571f2d40bf1dd1955a63d6eeb5",
                "sha256:c6f981882aea41e021f72779ce2a4e87267458cc4d39ea990729e21ef18f0f8c",
                "sha256:cc78cc83110d2f275ec1970e7a831f4e371ee92405332ebfe9860a715f8336e1",
                "sha256:d49f3db871575e0426b12e2f32fdb25e579dea16486a26e5a0474af87cb1ab0a",
                "sha256:dd3f9a40c16daf323cf913593083698caee97df2804aa36c4b3175d5ac1b92a2",
                "sha256:e0bedafe4bc165ad0a56ac0bd7695df25c50f76961da29c050712596cf092d6d",
                "sha256:e9069e1b01525a96e6ff49e25876d90d5a563bc31c658289a8772ae186552236"
            ],
            "index": "pypi",
            "version": "==1.10.2"
        },
        "typing-extensions": {
            "hashes": [
                "sha256:1511434bb92bf8dd198c12b1cc812e800d4181cfcb867674e0f8279cc93087aa",
                "sha256:16fa4864408f655d35ec496218b85f79b3437c829e93320c7c9215ccfd92489e"
            ],
            "markers": "python_version >= '3.7'",
            "version": "==4.4.0"
        }
    },
    "develop": {}
}

```
</details>



Discussion:
I just verified this behavior is happening, but my initial attempted fix was unsuccessful.  I see @oz123 self assigned so I'll let him have a go at it next.
I have a fix for this, opening a PR now.

Resolving patch:
diff --git a/pipenv/utils/dependencies.py b/pipenv/utils/dependencies.py
--- a/pipenv/utils/dependencies.py
+++ b/pipenv/utils/dependencies.py
@@ -234,7 +234,8 @@ def clean_resolved_dep(dep, is_top_level=False, pipfile_entry=None):
         else:
             try:
                 pipfile_entry = translate_markers(pipfile_entry)
-                lockfile["markers"] = pipfile_entry.get("markers")
+                if pipfile_entry.get("markers"):
+                    lockfile["markers"] = pipfile_entry.get("markers")
             except TypeError:
                 pass
     return {name: lockfile}


Test patch:
diff --git a/tests/integration/test_lock.py b/tests/integration/test_lock.py
--- a/tests/integration/test_lock.py
+++ b/tests/integration/test_lock.py
@@ -1,6 +1,5 @@
 import json
 import os
-import sys
 from pathlib import Path
 
 import pytest
@@ -719,3 +718,17 @@ def test_lock_specific_named_category(pipenv_instance_private_pypi):
         assert c.returncode == 0
         assert p.lockfile["prereq"]["six"]["index"] == "test"
         assert p.lockfile["default"]["requests"]["index"] == "test"
+
+def test_pinned_pipfile_no_null_markers_when_extras(pipenv_instance_pypi):
+    with pipenv_instance_pypi() as p:
+        with open(p.pipfile_path, "w") as f:
+            contents = """
+[packages]
+dataclasses-json = {extras = ["dev"], version = "==0.5.7"}
+            """.strip()
+            f.write(contents)
+        c = p.pipenv("lock")
+        assert c.returncode == 0
+        assert "dataclasses-json" in p.pipfile["packages"]
+        assert "dataclasses-json" in p.lockfile["default"]
+        assert "markers" not in p.lockfile["default"]["dataclasses-json"]
\ No newline at end of file