jacebrowning / datafiles

A file-based ORM for Python dataclasses.
https://datafiles.readthedocs.io
MIT License
198 stars 18 forks source link

`Manager.get` fix #289

Closed bnorick closed 1 year ago

bnorick commented 1 year ago

I updated Manager.get to be a bit more flexible. It now allows only the arguments which are required for path construction, i.e., those which appear in the pattern, to be passed either as args or kwargs. Previously, passing as kwargs only when multiple non-default fields existed would fail as in the example below, and there may have been other bugs with the previous implementation that I didn't discover.

@datafiles.datafile('{self.a}.toml', manual=True)
class T2:
    a: int
    b: int

T2.objects.get(a=5)

# Results in the following in main, works in PR
# Traceback (most recent call last):
#   File "<stdin>", line 1, in <module>
#   File "/path/to/repo/datafiles/manager.py", line 43, in get
#     instance = self.model(*args, **kwargs)
#                ^^^^^^^^^^^^^^^^^^^^^^^^^^^
#   File "/path/to/repo/datafiles/model.py", line 82, in modified_init
#     init(self, *args, **kwargs)
# TypeError: T2.__init__() got multiple values for argument 'a'