# Buggy code
def get_lockfile_meta(self):
    from .vendor.plette.lockfiles import PIPFILE_SPEC_CURRENT

    if self.lockfile_exists:
        sources = self.lockfile_content.get("_meta", {}).get("sources", [])
    else:
        sources = [dict(source) for source in self.parsed_pipfile["source"]]
    if not isinstance(sources, list):
        sources = [sources]
    return {
        "hash": {"sha256": self.calculate_pipfile_hash()},
        "pipfile-spec": PIPFILE_SPEC_CURRENT,
        "sources": [self.populate_source(s) for s in sources],
        "requires": self.parsed_pipfile.get("requires", {}),
    }


# Traceback (tomlkit.exceptions.NonExistentKey)
Installing dependencies from Pipfile…
Traceback (most recent call last):
File "/opt/miniconda3/bin/pipenv", line 8, in <module>
sys.exit(cli())
File "/opt/miniconda3/lib/python3.7/site-packages/pipenv/vendor/click/core.py", line 764, in __call__
return self.main(*args, **kwargs)
File "/opt/miniconda3/lib/python3.7/site-packages/pipenv/vendor/click/core.py", line 717, in main
rv = self.invoke(ctx)
File "/opt/miniconda3/lib/python3.7/site-packages/pipenv/vendor/click/core.py", line 1137, in invoke
return _process_result(sub_ctx.command.invoke(sub_ctx))
File "/opt/miniconda3/lib/python3.7/site-packages/pipenv/vendor/click/core.py", line 956, in invoke
return ctx.invoke(self.callback, **ctx.params)
File "/opt/miniconda3/lib/python3.7/site-packages/pipenv/vendor/click/core.py", line 555, in invoke
return callback(*args, **kwargs)
File "/opt/miniconda3/lib/python3.7/site-packages/pipenv/vendor/click/decorators.py", line 64, in new_func
return ctx.invoke(f, obj, *args, **kwargs)
File "/opt/miniconda3/lib/python3.7/site-packages/pipenv/vendor/click/core.py", line 555, in invoke
return callback(*args, **kwargs)
File "/opt/miniconda3/lib/python3.7/site-packages/pipenv/vendor/click/decorators.py", line 17, in new_func
return f(get_current_context(), *args, **kwargs)
File "/opt/miniconda3/lib/python3.7/site-packages/pipenv/cli/command.py", line 254, in install
editable_packages=state.installstate.editables,
File "/opt/miniconda3/lib/python3.7/site-packages/pipenv/core.py", line 1874, in do_install
keep_outdated=keep_outdated
File "/opt/miniconda3/lib/python3.7/site-packages/pipenv/core.py", line 1253, in do_init
pypi_mirror=pypi_mirror,
File "/opt/miniconda3/lib/python3.7/site-packages/pipenv/core.py", line 795, in do_install_dependencies
lockfile = project.get_or_create_lockfile(from_pipfile=True)
File "/opt/miniconda3/lib/python3.7/site-packages/pipenv/project.py", line 754, in get_or_create_lockfile
lockfile_dict.update({"_meta": self.get_lockfile_meta()})
File "/opt/miniconda3/lib/python3.7/site-packages/pipenv/project.py", line 790, in get_lockfile_meta
sources = [dict(source) for source in self.parsed_pipfile["source"]]
File "/opt/miniconda3/lib/python3.7/site-packages/pipenv/vendor/tomlkit/container.py", line 500, in __getitem__
raise NonExistentKey(key)
tomlkit.exceptions.NonExistentKey: 'Key "source" does not exist.'

# Fixed code
def get_lockfile_meta(self):
    from .vendor.plette.lockfiles import PIPFILE_SPEC_CURRENT

    if self.lockfile_exists:
        sources = self.lockfile_content.get("_meta", {}).get("sources", [])
    elif "source" in self.parsed_pipfile:
        sources = [dict(source) for source in self.parsed_pipfile["source"]]
    else:
        sources = self.pipfile_sources
    if not isinstance(sources, list):
        sources = [sources]
    return {
        "hash": {"sha256": self.calculate_pipfile_hash()},
        "pipfile-spec": PIPFILE_SPEC_CURRENT,
        "sources": [self.populate_source(s) for s in sources],
        "requires": self.parsed_pipfile.get("requires", {}),
    }