poetry icon indicating copy to clipboard operation
poetry copied to clipboard

poetry self update fails if poetry.lock in config dir is old

Open andyhasit opened this issue 3 years ago • 1 comments

  • Poetry version: error updating from 1.2.0 to 1.3.1
  • Python version:3.10.4
  • OS version and name: Linux Mint 18
  • pyproject.toml: N/A multiple.
  • [x] I am on the latest stable Poetry version, installed using a recommended method.
  • [x] I have searched the issues of this repo and believe that this is not a duplicate.
  • [x] I have consulted the FAQ and blog for any relevant entries or release notes.
  • [x] If an exception occurs when executing a command, I executed it again in debug mode (-vvv option) and have included the output below.

Issue

I am attempting to update from poetry 1.2 to 1.3 using poetry self update. Poetry 1.2 was installed using the new installer (I had to do it recently as poetry self update didn't get me from 1.1 to 1.2) but get the following error:

The lock file is not compatible with the current version of Poetry.

Which does not make sense as I am not running it from a directory which has a poetry.lock file.

Output with -vvv flag:

$ poetry self update -vvv
Loading configuration file /home/andrew/.config/pypoetry/config.toml
Updating Poetry version ...

[keyring.backend] Loading KWallet
[keyring.backend] Loading SecretService
[keyring.backend] Loading Windows
[keyring.backend] Loading chainer
[keyring.backend] Loading libsecret
[keyring.backend] Loading macOS
Creating new session for pypi.org
Source (PyPI): 85 packages found for poetry *
Using version ^1.3.1 for poetry


  Stack trace:

  16  ~/.local/share/pypoetry/venv/lib/python3.10/site-packages/cleo/application.py:329 in run
       327│ 
       328│             try:
     → 329│                 exit_code = self._run(io)
       330│             except Exception as e:
       331│                 if not self._catch_exceptions:

  15  ~/.local/share/pypoetry/venv/lib/python3.10/site-packages/poetry/console/application.py:185 in _run
       183│         self._load_plugins(io)
       184│ 
     → 185│         exit_code: int = super()._run(io)
       186│         return exit_code
       187│ 

  14  ~/.local/share/pypoetry/venv/lib/python3.10/site-packages/cleo/application.py:423 in _run
       421│             io.input.set_stream(stream)
       422│ 
     → 423│         exit_code = self._run_command(command, io)
       424│         self._running_command = None
       425│ 

  13  ~/.local/share/pypoetry/venv/lib/python3.10/site-packages/cleo/application.py:465 in _run_command
       463│ 
       464│         if error is not None:
     → 465│             raise error
       466│ 
       467│         return event.exit_code

  12  ~/.local/share/pypoetry/venv/lib/python3.10/site-packages/cleo/application.py:449 in _run_command
       447│ 
       448│             if event.command_should_run():
     → 449│                 exit_code = command.run(io)
       450│             else:
       451│                 exit_code = ConsoleCommandEvent.RETURN_CODE_DISABLED

  11  ~/.local/share/pypoetry/venv/lib/python3.10/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:

  10  ~/.local/share/pypoetry/venv/lib/python3.10/site-packages/cleo/commands/command.py:83 in execute
        81│ 
        82│         try:
     →  83│             return self.handle()
        84│         except KeyboardInterrupt:
        85│             return 1

   9  ~/.local/share/pypoetry/venv/lib/python3.10/site-packages/poetry/console/commands/self/self_command.py:130 in handle
       128│ 
       129│         with directory(self.system_pyproject.parent):
     → 130│             return self._system_project_handle()
       131│ 

   8  ~/.local/share/pypoetry/venv/lib/python3.10/site-packages/poetry/console/commands/self/update.py:51 in _system_project_handle
        49│             argv.append("--allow-prereleases")
        50│ 
     →  51│         exit_code: int = add_command.run(
        52│             IO(
        53│                 StringInput(" ".join(argv)),

   7  ~/.local/share/pypoetry/venv/lib/python3.10/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:
Loading configuration file /home/andrew/.config/pypoetry/config.toml
   6  ~/.local/share/pypoetry/venv/lib/python3.10/site-packages/cleo/commands/command.py:83 in execute
        81│ 
        82│         try:
     →  83│             return self.handle()
        84│         except KeyboardInterrupt:
        85│             return 1

   5  ~/.local/share/pypoetry/venv/lib/python3.10/site-packages/poetry/console/commands/add.py:251 in handle
       249│         self.installer.whitelist([r["name"] for r in requirements])
       250│ 
     → 251│         status = self.installer.run()
       252│ 
       253│         if status == 0 and not self.option("dry-run"):

   4  ~/.local/share/pypoetry/venv/lib/python3.10/site-packages/poetry/installation/installer.py:111 in run
       109│             self._execute_operations = False
       110│ 
     → 111│         return self._do_install()
       112│ 
       113│     def dry_run(self, dry_run: bool = True) -> Installer:

   3  ~/.local/share/pypoetry/venv/lib/python3.10/site-packages/poetry/installation/installer.py:218 in _do_install
       216│         locked_repository = Repository("poetry-locked")
       217│         if self._update:
     → 218│             if self._locker.is_locked() and not self._lock:
       219│                 locked_repository = self._locker.locked_repository()
       220│ 

   2  ~/.local/share/pypoetry/venv/lib/python3.10/site-packages/poetry/packages/locker.py:73 in is_locked
        71│             return False
        72│ 
     →  73│         return "package" in self.lock_data
        74│ 
        75│     def is_fresh(self) -> bool:

   1  ~/.local/share/pypoetry/venv/lib/python3.10/site-packages/poetry/packages/locker.py:62 in lock_data
        60│     def lock_data(self) -> TOMLDocument:
        61│         if self._lock_data is None:
     →  62│             self._lock_data = self._get_lock_data()
        63│ 
        64│         return self._lock_data

  RuntimeError

  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.

  at ~/.local/share/pypoetry/venv/lib/python3.10/site-packages/poetry/packages/locker.py:297 in _get_lock_data
      293│                 " alternatively, regenerate the lock file with the `poetry lock`"
      294│                 " command."
      295│             )
      296│         elif not lock_version_allowed:
    → 297│             raise RuntimeError(
      298│                 "The lock file is not compatible with the current version of Poetry.\n"
      299│                 "Upgrade Poetry to be able to read the lock file or, alternatively, "
      300│                 "regenerate the lock file with the `poetry lock` command."
      301│             )

This shows me it is using the configuration file /home/andrew/.config/pypoetry/config.toml

So I went and deleted /home/andrew/.config/pypoetry/poetry.lock and installation now works.

I think we could change the update script to delete that lock file prior to update, just in case it's an incompatible version.

andyhasit avatar Dec 22 '22 12:12 andyhasit

I ran into the same problem on Ubuntu 22.04 LTS, Python 3.10.6 and Poetry 1.2.1. Deleting the lock file also fixed the issue for me.

dargueta avatar Feb 20 '23 14:02 dargueta