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

Unclear error report: KeyError 'name' #8122

Closed
4 tasks done
td-anne opened this issue Jun 21, 2023 · 8 comments · Fixed by #8691
Closed
4 tasks done

Unclear error report: KeyError 'name' #8122

td-anne opened this issue Jun 21, 2023 · 8 comments · Fixed by #8691
Labels
area/error-handling Bad error messages/insufficient error handling kind/bug Something isn't working as expected

Comments

@td-anne
Copy link

td-anne commented Jun 21, 2023

  • I am on the latest stable Poetry version, installed using a recommended method.
  • I have searched the issues of this repo and believe that this is not a duplicate.
  • I have consulted the FAQ and blog for any relevant entries or release notes.
  • If an exception occurs when executing a command, I executed it again in debug mode (-vvv option) and have included the output below.

Issue

When I try poetry commands I get a failure with unhelpful output:

$ poetry debug info

Poetry

'name'

If I use -vvv it seems this is a KeyError emanating from inside poetry:

$ poetry debug info -vvv

Poetry

  Stack trace:

  12  ~/.local/share/pypoetry/venv/lib/python3.8/site-packages/cleo/application.py:327 in run
       325│ 
       326│             try:
     → 327│                 exit_code = self._run(io)
       328│             except BrokenPipeError:
       329│                 # If we are piped to another process, it may close early and send a

  11  ~/.local/share/pypoetry/venv/lib/python3.8/site-packages/poetry/console/application.py:190 in _run
       188│         self._load_plugins(io)
       189│ 
     → 190│         exit_code: int = super()._run(io)
       191│         return exit_code
       192│ 

  10  ~/.local/share/pypoetry/venv/lib/python3.8/site-packages/cleo/application.py:431 in _run
       429│             io.input.interactive(interactive)
       430│ 
     → 431│         exit_code = self._run_command(command, io)
       432│         self._running_command = None
       433│ 

   9  ~/.local/share/pypoetry/venv/lib/python3.8/site-packages/cleo/application.py:473 in _run_command
       471│ 
       472│         if error is not None:
     → 473│             raise error
       474│ 
       475│         return terminate_event.exit_code

   8  ~/.local/share/pypoetry/venv/lib/python3.8/site-packages/cleo/application.py:457 in _run_command
       455│ 
       456│             if command_event.command_should_run():
     → 457│                 exit_code = command.run(io)
       458│             else:
       459│                 exit_code = ConsoleCommandEvent.RETURN_CODE_DISABLED

   7  ~/.local/share/pypoetry/venv/lib/python3.8/site-packages/cleo/commands/base_command.py:119 in run
       117│         io.input.validate()
       118│ 
     → 119│         status_code = self.execute(io)
       120│ 
       121│         if status_code is None:

   6  ~/.local/share/pypoetry/venv/lib/python3.8/site-packages/cleo/commands/command.py:62 in execute
        60│ 
        61│         try:
     →  62│             return self.handle()
        63│         except KeyboardInterrupt:
        64│             return 1

   5  ~/.local/share/pypoetry/venv/lib/python3.8/site-packages/poetry/console/commands/debug/info.py:20 in handle
        18│             "\n".join(
        19│                 [
     →  20│                     f"Version: {self.poetry.VERSION}",
        21│                     f"Python:  {poetry_python_version}",
        22│                 ]

   4  ~/.local/share/pypoetry/venv/lib/python3.8/site-packages/poetry/console/commands/command.py:23 in poetry
        21│     def poetry(self) -> Poetry:
        22│         if self._poetry is None:
     →  23│             return self.get_application().poetry
        24│ 
        25│         return self._poetry

   3  ~/.local/share/pypoetry/venv/lib/python3.8/site-packages/poetry/console/application.py:129 in poetry
       127│             project_path = self._io.input.option("directory")
       128│ 
     → 129│         self._poetry = Factory().create_poetry(
       130│             cwd=project_path,
       131│             io=self._io,

   2  ~/.local/share/pypoetry/venv/lib/python3.8/site-packages/poetry/factory.py:58 in create_poetry
        56│             io = NullIO()
        57│ 
     →  58│         base_poetry = super().create_poetry(cwd=cwd, with_groups=with_groups)
        59│ 
        60│         poetry_file = base_poetry.pyproject_path

   1  ~/.local/share/pypoetry/venv/lib/python3.8/site-packages/poetry/core/factory.py:52 in create_poetry
        50│ 
        51│         # Checking validity
     →  52│         check_result = self.validate(local_config)
        53│         if check_result["errors"]:
        54│             message = ""

  KeyError

  'name'

  at ~/.local/share/pypoetry/venv/lib/python3.8/site-packages/poetry/factory.py:370 in validate
      366│             dependencies.update(group.get("dependencies", {}).keys())
      367│ 
      368│         dependencies = {canonicalize_name(d) for d in dependencies}
      369│ 
    → 370│         if canonicalize_name(config["name"]) in dependencies:
      371│             results["errors"].append(
      372│                 f"Project name ({config['name']}) is same as one of its dependencies"
      373│             )
      374│ 

This is probably because of something amiss in my pyproject.toml but the error message provides no indication of what.

@td-anne td-anne added kind/bug Something isn't working as expected status/triage This issue needs to be triaged labels Jun 21, 2023
@dimbleby
Copy link
Contributor

diff --git a/src/poetry/factory.py b/src/poetry/factory.py
index 5e926b61..be6870f3 100644
--- a/src/poetry/factory.py
+++ b/src/poetry/factory.py
@@ -367,9 +367,10 @@ class Factory(BaseFactory):

         dependencies = {canonicalize_name(d) for d in dependencies}

-        if canonicalize_name(config["name"]) in dependencies:
+        project_name = config.get("name")
+        if project_name is not None and canonicalize_name(project_name) in dependencies:
             results["errors"].append(
-                f"Project name ({config['name']}) is same as one of its dependencies"
+                f"Project name ({project_name}) is same as one of its dependencies"
             )

         return results

should fix it

pull requests welcome, I'm sure

@kevinzeidler

This comment was marked as off-topic.

@dimbleby
Copy link
Contributor

@kevinzeidler that is completely different, please don't hijack this issue

@kevinzeidler
Copy link

You're right, my bad. Wasn't reading the stack traces carefully enough.

@GAC-BSP
Copy link

GAC-BSP commented Jul 9, 2023

Same here! Not sure how to workaround the issue.

@TravisBumgarner
Copy link

Whelp getting this error too.

@TravisBumgarner
Copy link

TravisBumgarner commented Nov 18, 2023

Alright so what I gathered is

[project]
name = "gcode2dplotterart"
version = "0.0.1"
description = "Easily generate plotter art with your 2D Plotter or 3D Printer. This library abstracts away G-Code so you can focus on making art."
authors = [
  { name="Travis Bumgarner", email="[email protected]" },
]

[build-system]
requires = ["hatchling", "setuptools", "wheel"]
build-backend = "hatchling.build"

[tool.poetry.dependencies]
python = "^3.11.5"
mypy="^1.7.0"
black="^23.10.1"
flake8="^6.1.0"
pytest="^7.4.3"
matplotlib="^3.8.1"
numpy="^1.26.1"
setuptools = "^68.2.2"
wheel = "^0.41.3"
pydoc-markdown = "^4.8.2"

[project.urls]
"Homepage" = "https://github.com/TravisBumgarner/gcode2dplotterart"
"Bug Tracker" = "https://github.com/TravisBumgarner/gcode2dplotterart/issues"

This was my pyproject.toml.

I added the section

[tool.poetry]
name = "gcode2dplotterart"
authors = ["Travis Bumgarner"]
version = "0.0.1"
description = "Easily generate plotter art with your 2D Plotter or 3D Printer. This library abstracts away G-Code so you can focus on making art."

Which is really just a duplicate of the [project] section. But the error went away.

dimbleby added a commit to dimbleby/poetry that referenced this issue Nov 19, 2023
@radoering radoering added area/error-handling Bad error messages/insufficient error handling and removed status/triage This issue needs to be triaged labels Nov 19, 2023
Copy link

This issue has been automatically locked since there has not been any recent activity after it was closed. Please open a new issue for related bugs.

@github-actions github-actions bot locked as resolved and limited conversation to collaborators Feb 29, 2024
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
area/error-handling Bad error messages/insufficient error handling kind/bug Something isn't working as expected
Projects
None yet
Development

Successfully merging a pull request may close this issue.

6 participants