django / django/new-features

add update_fields to FieldFile.save when save=True

Open
#48 4 comments 7 reactions 0 assignees View on GitHub
Django Core Documentation Models/ORM
Dominant language
No language data
Stars
188
Forks
7
PR merge metrics
No merged PRs in 30d

Description

### Code of Conduct

- [x] I agree to follow Django's Code of Conduct

### Feature Description

The current implementation of FieldFile.save (ref: https://github.com/django/django/blob/cf1a80fc2d19f359744a20bb6cb1f0a169ef506b/django/db/models/fields/files.py#L96-L105 ) automatically saves _all_ fields when the save argument is True i.e. `.save(..., save=True)`

This new feature will add support for passing `update_fields` like one does in Model.save we'll then just forward them to the instance.save

### Problem

Currently, it's not possible to limit the scope of which fields are saved when a `FieldField.save` is called with `save=True`.

As stated in the docs:
1. This may be desirable if you want to update just one or a few fields on an object.
2. There will be a slight performance benefit from preventing all of the model fields from being updated in the database.

Also, for us, in practice, lacking this worsens the situation when race conditions occur.

### Request or proposal

proposal

### Additional Details

First time contributor. Please feel free to point things out to me.

### Implementation Suggestions

seems to me that a simple passthrough will be sufficient. However, there's a question of whether the field in question should _always_ be included in the update_fields

Contributor guide

No contributing guide indexed for this repository

Assessment

This issue has not been assessed yet.

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.