Skip to content

add update_fields to FieldFile.save when save=True #48

Open
@do-rtk

Description

@do-rtk

Code of Conduct

  • 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

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type

    Projects

    Status

    Idea

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions