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

poetry lock should overwrite broken poetry.lock file, not error out. #1196

Closed
dimaqq opened this issue Jun 26, 2019 · 8 comments · Fixed by #6753
Closed

poetry lock should overwrite broken poetry.lock file, not error out. #1196

dimaqq opened this issue Jun 26, 2019 · 8 comments · Fixed by #6753
Labels
area/error-handling Bad error messages/insufficient error handling area/ux Features and improvements related to the user experience kind/feature Feature requests/implementations

Comments

@dimaqq
Copy link
Contributor

dimaqq commented Jun 26, 2019

… ~/my_project> poetry shell

[EmptyKeyError]
Empty key at line 36 col 0

shell

The actual reason is that I have a merge conflict in pyproject.toml.
I wish poetry told me that! 🙏

Also, if the merge conflict is in poetry.lock the best action to resolve it is seemingly to run poetry lock (assuming project is close to HEAD and not some old branch merged with another old branch).

(poetry versions tested: 1.0.0a2 1.0.0a4 0.12.16)

@kasteph kasteph added the kind/feature Feature requests/implementations label Jun 26, 2019
@dimaqq
Copy link
Contributor Author

dimaqq commented Oct 25, 2019

… ~/myproj> git rebase origin/HEAD
...
M	poetry.lock
Falling back to patching base and 3-way merge...
Auto-merging poetry.lock
CONFLICT (content): Merge conflict in poetry.lock
error: Failed to merge in the changes.
...
… ~/myproj> poetry lock

[EmptyKeyError]
Empty key at line 1896 col 0

Still a problem with poetry==1.0.0b2

@dimaqq dimaqq changed the title Better error on broken input files poetry lock should overwrite broken poetry.lock file, not error out. Oct 25, 2019
@eikevons
Copy link

Would a --force flag help here, that ignores any existing content in poetry.lock. That way we avoid silently overwriting inconsistent lock states.

@sinoroc
Copy link

sinoroc commented Nov 17, 2020

@dimaqq Does the issue still exist in newer poetry versions (>=1.1)?

@eikevons
Copy link

I can confirm that a broken poetry.lock still makes poetry lock to throw an error.

In a fresh Python 3.8 with poetry 1.1.4 I get (I broke poetry.lock by emptying all content)

 poetry lock

  NonExistentKey

  'Key "metadata" does not exist.'

  at ~/.poetry/lib/poetry/_vendor/py3.8/tomlkit/container.py:576 in __getitem__
      572│             key = Key(key)
      573│ 
      574│         idx = self._map.get(key, None)
      575│         if idx is None:
    → 576│             raise NonExistentKey(key)
      577│ 
      578│         if isinstance(idx, tuple):
      579│             # The item we are getting is an out of order table
      580│             # so we need a proxy to retrieve the proper objects

Steps to reproduce with docker:

  • create test.sh:
    #!/bin/sh
    
    set -xe
    
    apt-get update -q
    apt-get install --yes -q curl
    curl -sSL https://raw.githubusercontent.com/python-poetry/poetry/master/get-poetry.py | python
    . "$HOME/.poetry/env"
    mkdir -p /app
    cd /app
    poetry init -n -q
    poetry add -n -q requests
    echo -n > poetry.lock
    poetry lock
  • run test.sh: docker run --rm -ti --volume "$PWD/test.sh:/test.sh:ro" python:3.8-slim sh /test.sh

@finswimmer finswimmer added area/cli Related to the command line area/ux Features and improvements related to the user experience labels Nov 20, 2020
@phillipuniverse
Copy link

Confirmed still an issue in 1.1.6. Looks like the only fix is rm poetry.lock && poetry lock.

The problem with that is that this will implicitly update dependencies, since you removed poetry.lock the --no-update doesn't actually do anything.

@kkirsche
Copy link
Contributor

kkirsche commented Sep 21, 2021

If there are concerns about the scope of this type of change, an alternative solution would be to restrict when situations overwriting or "fixing" the lockfile occurs. For example, automate fixing merge conflicts potentially as yarn does? Overall, a smaller scope allows for alternative technical implementations to be used in order to satisfy the requirement.

EDIT: Fixed grammatical issues

@passionsfrucht
Copy link

Not really a solution, but a tip, or how I integrate it in my workflow regarding --no-update. It usually happens when I do a rebase, thus to hinder it to do an unintended upgrade:

$ git checkout origin/master -- poetry.lock
??? updated 1 file ???
$ poetry lock --no-update

I'm quite positive that it can be done in a more elegant way using --ours or some .gitattributes magic with a check if the lock file needs an update, but this way it is good enough for me right now.

So maybe it can be handled as a documentation issue?

Disclaimer: I just looked it up in my command history. And wrote the results how I remembered it, I may have got a detail wrong.

@neersighted neersighted added area/error-handling Bad error messages/insufficient error handling and removed area/cli Related to the command line labels Oct 4, 2022
neersighted pushed a commit that referenced this issue Oct 10, 2022
…e exists (#6753)

After having created a lock file 2.0, running `poetry lock` with poetry
1.2.1 results in the following output:

```
The lock file is not compatible with the current version of Poetry.
Upgrade Poetry to be able to read the lock file or, alternatively, regenerate the lock file with the `poetry lock` command.
```

Ironically, the error message proposes to run `poetry lock` which
results in this error message.

Further, it doesn't make sense that `poetry lock` fails because it
creates a new lock file from scratch (in contrast to `poetry lock
--no-update`).

Running `poetry lock` is now also possible if there is a broken lock file.

Resolves: #1196
poetry-bot bot pushed a commit that referenced this issue Oct 10, 2022
…e exists (#6753)

After having created a lock file 2.0, running `poetry lock` with poetry
1.2.1 results in the following output:

```
The lock file is not compatible with the current version of Poetry.
Upgrade Poetry to be able to read the lock file or, alternatively, regenerate the lock file with the `poetry lock` command.
```

Ironically, the error message proposes to run `poetry lock` which
results in this error message.

Further, it doesn't make sense that `poetry lock` fails because it
creates a new lock file from scratch (in contrast to `poetry lock
--no-update`).

Running `poetry lock` is now also possible if there is a broken lock file.

Resolves: #1196
(cherry picked from commit 7d414af)
neersighted pushed a commit that referenced this issue Oct 10, 2022
…e exists (#6753)

After having created a lock file 2.0, running `poetry lock` with poetry
1.2.1 results in the following output:

```
The lock file is not compatible with the current version of Poetry.
Upgrade Poetry to be able to read the lock file or, alternatively, regenerate the lock file with the `poetry lock` command.
```

Ironically, the error message proposes to run `poetry lock` which
results in this error message.

Further, it doesn't make sense that `poetry lock` fails because it
creates a new lock file from scratch (in contrast to `poetry lock
--no-update`).

Running `poetry lock` is now also possible if there is a broken lock file.

Resolves: #1196
(cherry picked from commit 7d414af)
Copy link

github-actions bot commented Mar 1, 2024

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 Mar 1, 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 area/ux Features and improvements related to the user experience kind/feature Feature requests/implementations
Projects
None yet
Development

Successfully merging a pull request may close this issue.

9 participants