sarugaku / plette

Structured Pipfile and Pipfile.lock models.
ISC License
7 stars 7 forks source link

Infinite loop/recursion error when accessing `LockFile` properties via `__getitem__` #54

Closed mcrichton closed 2 months ago

mcrichton commented 5 months ago

Affects:

plette version 1.0.0

Expected:

accessing lockfile["default"] should return the same value as lockfile.default

Actual:

accessing lockfile["default"] causes an infinite loop (RecursionError)

Cause:

my_lockfile["default"] -> __getitem__(self, "default") -> value = self["default"] -> __getitem__(self, "default") -> ...

Repro:

Using (an admittedly outdated version of) requirementslib with latest plette. Affected line here: https://github.com/sarugaku/requirementslib/blob/d6b5165bfc6f043b1156c209d85f3e09b60aeaa8/src/requirementslib/models/lockfile.py#L79

Can also be easily repro'd in tests by doing lock["default"]

Notes:

The tests in https://github.com/sarugaku/plette/blob/master/tests/test_lockfiles.py do not catch this issue, as they use lock.<...> rather than lock[<...>]

oz123 commented 4 months ago

This should be fixed by #55

Please verify by:

python -i -m plette -f Pipfile.lock
>>> lockfile.dev_packages
>>> lockfile.develop
mcrichton commented 3 months ago

Tested and working, thank you.

The only change I had to make was removing the (unused) import tomllib as I am using Python 3.10: https://github.com/mcrichton/plette/commit/b395ca8ddb6d4871e9d3800a4fdc2d0234430323

oz123 commented 2 months ago

Fixed in v2.0.0