Opened 3 years ago

Closed 3 years ago

#18362 closed Bug (fixed)

model save with update_fields should accept both field.name and field.attname

Reported by: akaariai Owned by: nobody
Component: Database layer (models, ORM) Version: master
Severity: Normal Keywords:
Cc: niwi@… Triage Stage: Accepted
Has patch: yes Needs documentation: no
Needs tests: no Patch needs improvement: no
Easy pickings: no UI/UX: no

Description

Currently only field.name is accepted in update_fields argument. It seems field.attname should be accepted, too. Most commonly this will be encountered when trying to save a related field by "_id" appendix - for example update_fields=profile? will work, but update_fieldsprofile_id? will not work currently.

In my opinion this should work, as profile_id works in many other places, too, and this could be useful for automatic tracking of field changes for example.

Refs #4102, #18306.

Change History (3)

comment:1 Changed 3 years ago by akaariai

  • Needs documentation unset
  • Needs tests unset
  • Patch needs improvement unset
  • Triage Stage changed from Unreviewed to Accepted

hmmh - I can't edit the description. so, in above the examples are "update_fields=['profile']/['profile_id']" instead of the helpful wiki-links...

comment:2 Changed 3 years ago by niwi

  • Cc niwi@… added
  • Has patch set

comment:3 Changed 3 years ago by Anssi Kääriäinen <akaariai@…>

  • Resolution set to fixed
  • Status changed from new to closed

In [0f49b2bce2d5b3c5891c8a329bab7dffe16fc79b]:

Fixed #18362 - Made model.save() update_fields accept attnames

Note: See TracTickets for help on using tickets.
Back to Top