jacebrowning / jacebrowning/datafiles
Allow synchronization of filename attributes
Nobody has claimed this yet.
- Dominant language
- Python
- Stars
- 213
- Forks
- 23
- Avg merge
- 1d 22h
- Merged PRs (30d)
- 5
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:
```python
@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`).
Contributor guide
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- Open a pull request that references the issue number.
Research direction
Start with the datafiles.datafile decorator and the Person example, focusing on how changes to attributes represented in the filename are persisted. Decide whether those attributes should be frozen or whether an optional rename=True behavior should be supported. Done means the chosen behavior keeps the filename and model values consistent after modification.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- python
- Domain
- databases
- Issue type
- Feature
- Difficulty
- 5/5
- Estimated time
- Over a week
- Activity status
- Stale
- Clarity
- Mostly clear
- Newbie friendliness
- 30/100