Skip to content

pdm export raises KeyError #1786

Closed
j178/pdm
#1
@he0119

Description

  • I have searched the issue tracker and believe that this is not a duplicate.

Make sure you run commands with -v flag before pasting the output.

Steps to reproduce

  1. checkout https://github.com/nonepkg/nonebot-plugin-all4one/tree/ci/docker
  2. pdm export

Actual behavior

❯ pdm export -v
The exported requirements file is no longer cross-platform. Using it on other platforms may cause unexpected result.
STATUS: Resolving packages from lockfile...
Traceback (most recent call last):
  File "<frozen runpy>", line 198, in _run_module_as_main
  File "<frozen runpy>", line 88, in _run_code
  File "c:\users\hmy01\.local\bin\pdm.exe\__main__.py", line 7, in <module>
  File "C:\Users\hmy01\.local\pipx\venvs\pdm\Lib\site-packages\pdm\core.py", line 247, in main
    return Core().main(args)
           ^^^^^^^^^^^^^^^^^
  File "C:\Users\hmy01\.local\pipx\venvs\pdm\Lib\site-packages\pdm\core.py", line 181, in main
    raise cast(Exception, err).with_traceback(traceback) from None
  File "C:\Users\hmy01\.local\pipx\venvs\pdm\Lib\site-packages\pdm\core.py", line 176, in main
    f(project, options)
  File "C:\Users\hmy01\.local\pipx\venvs\pdm\Lib\site-packages\pdm\cli\commands\export.py", line 74, in handle
    candidates = resolve_candidates_from_lockfile(project, requirements.values())
                 ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "C:\Users\hmy01\.local\pipx\venvs\pdm\Lib\site-packages\pdm\cli\actions.py", line 136, in resolve_candidates_from_lockfile
    mapping, *_ = resolve(
                  ^^^^^^^^
  File "C:\Users\hmy01\.local\pipx\venvs\pdm\Lib\site-packages\pdm\resolver\core.py", line 35, in resolve
    result = resolver.resolve(requirements, max_rounds)
             ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "C:\Users\hmy01\.local\pipx\venvs\pdm\Lib\site-packages\resolvelib\resolvers.py", line 521, in resolve
    state = resolution.resolve(requirements, max_rounds=max_rounds)
            ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "C:\Users\hmy01\.local\pipx\venvs\pdm\Lib\site-packages\resolvelib\resolvers.py", line 401, in resolve
    name = min(unsatisfied_names, key=self._get_preference)
           ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "C:\Users\hmy01\.local\pipx\venvs\pdm\Lib\site-packages\resolvelib\resolvers.py", line 202, in _get_preference
    return self._p.get_preference(
           ^^^^^^^^^^^^^^^^^^^^^^^
  File "C:\Users\hmy01\.local\pipx\venvs\pdm\Lib\site-packages\pdm\resolver\providers.py", line 84, in get_preference
    is_backtrack_cause = any(dep.identify() in backtrack_identifiers for dep in self.get_dependencies(candidate))
                                                                                ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "C:\Users\hmy01\.local\pipx\venvs\pdm\Lib\site-packages\pdm\resolver\providers.py", line 176, in get_dependencies
    deps, requires_python, _ = self.repository.get_dependencies(candidate)
                               ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "C:\Users\hmy01\.local\pipx\venvs\pdm\Lib\site-packages\pdm\models\repositories.py", line 81, in get_dependencies
    requirements, requires_python, summary = getter(candidate)
                                             ^^^^^^^^^^^^^^^^^
  File "C:\Users\hmy01\.local\pipx\venvs\pdm\Lib\site-packages\pdm\models\repositories.py", line 411, in _get_dependencies_from_lockfile
    return self.candidate_info[self._identify_candidate(candidate)]
           ~~~~~~~~~~~~~~~~~~~^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
KeyError: ('nonebot-adapter-onebot', '2.2.2', None, False)

Expected behavior

no error

Environment Information

❯ pdm info && pdm info --env
PDM version:
  2.4.9
Python Interpreter:
  C:\Users\hmy01\Works\Working\Bot\nonebot-plugin-all4one\.venv\Scripts\python.exe (3.11)
Project Root:
  C:/Users/hmy01/Works/Working/Bot/nonebot-plugin-all4one
Project Packages:
  None
{
  "implementation_name": "cpython",
  "implementation_version": "3.11.2",
  "os_name": "nt",
  "platform_machine": "AMD64",
  "platform_release": "10",
  "platform_system": "Windows",
  "platform_version": "10.0.22621",
  "python_full_version": "3.11.2",
  "platform_python_implementation": "CPython",
  "python_version": "3.11",
  "sys_platform": "win32"
}

Activity

he0119

he0119 commented on Mar 28, 2023

@he0119
Author

when I use pdm export --no-default, it works.

it seems default group overrides the other groups.

if default:
groups_set.add("default")

for group in selection:
requirements.update(project.get_dependencies(group))

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Assignees

No one assigned

    Labels

    🐛 bugSomething isn't working

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions

      `pdm export` raises `KeyError` · Issue #1786 · pdm-project/pdm