question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. ItΒ collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

AttributeError when adding a dependency group when private repo present (Poetry 1.2.0a2)

See original GitHub issue
  • I am on the latest Poetry version.
  • I have searched the issues of this repo and believe that this is not a duplicate.
  • If an exception occurs when executing a command, I executed it again in debug mode (-vvv option).

Not on latest, because I am on 1.2.0a2, which is newer than latest.

  • OS version and name: Linux Debian Bullseye in a container
  • Poetry version: 1.2.0a2
  • pyproject.toml file:
[tool.poetry]
name = "foobar"
version = "0.1.0"
description = ""
authors = ["Your Name <you@example.com>"]
readme = "README.md"

[tool.poetry.dependencies]
python = "^3.9"


[build-system]
requires = ["poetry-core"]
build-backend = "poetry.core.masonry.api"

[[tool.poetry.source]]
name = "foo"
url = "https://foo.bar/simple/"

Issue

When using a private repo (i.e. having a [[tool.poetry.source]] section to pyproject.toml), and adding a group dependency (e.g. running poetry add --group test pytest, e.g. the feature added in #4260) for a group that does not yet exist in the pyproject.toml, poetry raises an exception.

# poetry add --group test pytest

  AttributeError

  'dict' object has no attribute '_insert_after'

  at /usr/local/lib/python3.9/site-packagesconsole/commands/add.py:114 in handle
      110β”‚         else:
      111β”‚             if "group" not in poetry_content:
      112β”‚                 group_table = table()
      113β”‚                 group_table._is_super_table = True
    β†’ 114β”‚                 poetry_content.value._insert_after("dependencies", "group", group_table)
      115β”‚
      116β”‚             groups = poetry_content["group"]
      117β”‚             if group not in groups:
      118β”‚                 group_table = parse_toml(

Even though the example above has an invalid URL for the poetry source, this error happens even when the URL is valid and the necessary credentials to authenticate are present (e.g. a valid Google Artifact Repository repo), and regardless of whether the source is primary or secondary.

Also note that the dependency being added isn’t even hosted inside the private repo. (In this case, trying to add pytest to a group called β€œtest”.)

Removing the [[tool.poetry.source]] section allows Poetry to properly add the dependency group and dependency.

The above pyproject.toml was generated using the following:

docker run -it --rm python:3.9-slim-bullseye bash

# Within the container:
pip install poetry==1.2.0a2
poetry init --name foobar -n
cat >> pyproject.toml <<EOF

[[tool.poetry.source]]
name = "foo"
url = "https://foo.bar/simple/"
EOF
# Then run poetry add --group test pytest to see the error

Full output when running with -vvv

# poetry -vvv add pytest --group test
Loading configuration file /root/.config/pypoetry/config.toml
Adding repository phc (https://us-central1-python.pkg.dev/foobar/python/simple) and setting it as secondary
Using virtualenv: /venv

  Stack trace:

  7  /usr/local/lib/python3.9/site-packages/cleo/application.py:330 in run
      328β”‚
      329β”‚             try:
    β†’ 330β”‚                 exit_code = self._run(io)
      331β”‚             except Exception as e:
      332β”‚                 if not self._catch_exceptions:

  6  /usr/local/lib/python3.9/site-packages/poetry/console/application.py:180 in _run
      178β”‚         self._load_plugins(io)
      179β”‚
    β†’ 180β”‚         return super()._run(io)
      181β”‚
      182β”‚     def _configure_io(self, io: IO) -> None:

  5  /usr/local/lib/python3.9/site-packages/cleo/application.py:425 in _run
      423β”‚                 io.set_input(ArgvInput(argv))
      424β”‚
    β†’ 425β”‚         exit_code = self._run_command(command, io)
      426β”‚         self._running_command = None
      427β”‚

  4  /usr/local/lib/python3.9/site-packages/cleo/application.py:467 in _run_command
      465β”‚
      466β”‚         if error is not None:
    β†’ 467β”‚             raise error
      468β”‚
      469β”‚         return event.exit_code

  3  /usr/local/lib/python3.9/site-packages/cleo/application.py:451 in _run_command
      449β”‚
      450β”‚             if event.command_should_run():
    β†’ 451β”‚                 exit_code = command.run(io)
      452β”‚             else:
      453β”‚                 exit_code = ConsoleCommandEvent.RETURN_CODE_DISABLED

  2  /usr/local/lib/python3.9/site-packages/cleo/commands/base_command.py:118 in run
      116β”‚         io.input.validate()
      117β”‚
    β†’ 118β”‚         status_code = self.execute(io)
      119β”‚
      120β”‚         if status_code is None:

  1  /usr/local/lib/python3.9/site-packages/cleo/commands/command.py:85 in execute
       83β”‚
       84β”‚         try:
    β†’  85β”‚             return self.handle()
       86β”‚         except KeyboardInterrupt:
       87β”‚             return 1

  AttributeError

  'dict' object has no attribute '_insert_after'

  at /usr/local/lib/python3.9/site-packages/poetry/console/commands/add.py:114 in handle
      110β”‚         else:
      111β”‚             if "group" not in poetry_content:
      112β”‚                 group_table = table()
      113β”‚                 group_table._is_super_table = True
    β†’ 114β”‚                 poetry_content.value._insert_after("dependencies", "group", group_table)
      115β”‚
      116β”‚             groups = poetry_content["group"]
      117β”‚             if group not in groups:
      118β”‚                 group_table = parse_toml(

Issue Analytics

  • State:closed
  • Created 2 years ago
  • Reactions:1
  • Comments:6 (1 by maintainers)

github_iconTop GitHub Comments

3reactions
jbsilvacommented, Nov 27, 2021

An error in the same line happened with me when trying to add a new dev dependency to a project that was created with Poetry v1.1.11.

Replacing [tool.poetry.dev-dependencies] with [tool.poetry.group.dev.dependencies] solved the problem.

1reaction
lindycodercommented, Dec 21, 2021

I can reproduce quickly this with

poetry init -q
echo "\n[tool.poetry.plugins]" >> pyproject.toml
poetry add --group dev pytest

on

poetry --version
Poetry (version 1.2.0a2)

produces

Creating virtualenv demo in /private/tmp/demo/.venv

  AttributeError

  'dict' object has no attribute '_insert_after'

  at ~/Library/Application Support/pypoetry/venv/lib/python3.9/site-packages/poetry/console/commands/add.py:114 in handle
      110β”‚         else:
      111β”‚             if "group" not in poetry_content:
      112β”‚                 group_table = table()
      113β”‚                 group_table._is_super_table = True
    β†’ 114β”‚                 poetry_content.value._insert_after("dependencies", "group", group_table)
      115β”‚
      116β”‚             groups = poetry_content["group"]
      117β”‚             if group not in groups:
      118β”‚                 group_table = parse_toml(

I confirm that moving the [build-system] section at the end solves the problem

Read more comments on GitHub >

github_iconTop Results From Across the Web

Announcing Poetry 1.2.0a2 | Blog
The Poetry team is pleased to announce the immediate availability of Poetry 1.2.0a2. This release mainly adds support for dependency groups.
Read more >
Poetry trying to install everything from private repository
poetry first checks if the project is in your private-pypi and then checks public-pypi . Here the error is mostly because of 403...
Read more >
Announcing Poetry 1.2.0a2 (with dependency groups ...
Yes, dependency groups are separate from extras and won't appear in the package's metadata. They are a way to organize the development dependencies...
Read more >
Dependency Management With Python Poetry
Start a new Poetry project; Add Poetry to an existing project; Use the pyproject.toml file; Pin dependencies; Install dependencies with poetry.
Read more >
poetry
Poetry helps you declare, manage and install dependencies of Python projects, ensuring you have the right stack everywhere. Poetry Install. Poetry replacesΒ ...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found