Description
Currently, datafiles
handles any attributes that are part of the filepath as not being stored in the file itself. Personally I consider this a good design, as duplicating the value would potentially cause issues if the "filename" and "file content" values did not agree.
However, it seems we are unable to preserve any changes to the attributes that are part of the filename, effectively rendering them read-only. Consider a following datafile called JohnDoe.yml
:
age: 42
and an associated short script:
@datafiles.datafile("{self.name}.yml", defaults=True)
class Person:
name: str
age: int
person = list(Person.objects.all())[0]
print(person)
As expected, this will produce the following output:
Person(name='JohnDoe', age=42)
However, if we continue to modify the model instance:
person.name="BobBuilder"
person.age=24
we can observe on the filesystem that the file has been modified:
age: 24
however, the filename itself has not been changed, it is still JohnDoe.yml
, resulting in the following data:
Person(name='JohnDoe', age=24)
which does not align itself with the expected output from the viewpoint of the user. I would argue we should support one of the two options:
a) the "filename" attributes should be frozen and not allowed to be modified
b) or we should allow their modification, but rename the files, effectively preserving their modified value in the filename
If renaming is too drastic for it to be the default, we could perhaps have (a) as the default behaviour and allow (b) via an optional rename=True
flag (similar how we handle defaults=True
).