Re: [Django] #27017: Why doesn't Django's Model.save() save only the dirty fields by default? And how can I do that if I want?

2021-04-30 Thread Django
#27017: Why doesn't Django's Model.save() save only the dirty fields by default?
And how can I do that if I want?
-+-
 Reporter:  prajnamort   |Owner:  nobody
 Type:  Uncategorized|   Status:  closed
Component:  Database layer   |  Version:  1.8
  (models, ORM)  |
 Severity:  Normal   |   Resolution:  invalid
 Keywords:   | Triage Stage:
 |  Unreviewed
Has patch:  0|  Needs documentation:  0
  Needs tests:  0|  Patch needs improvement:  0
Easy pickings:  0|UI/UX:  0
-+-

Comment (by Jack Linke):

 Just a note for anyone coming across Andreas' comment above. django-
 dirtyfields does now make it possible to update only the dirty (changed)
 fields: https://django-dirtyfields.readthedocs.io/en/develop/#saving-
 dirty-fields

-- 
Ticket URL: 
Django 
The Web framework for perfectionists with deadlines.

-- 
You received this message because you are subscribed to the Google Groups 
"Django updates" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to django-updates+unsubscr...@googlegroups.com.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/django-updates/068.83b4cdb98237dce303f61868bd0727ee%40djangoproject.com.


Re: [Django] #27017: Why doesn't Django's Model.save() save only the dirty fields by default? And how can I do that if I want?

2020-02-26 Thread Django
#27017: Why doesn't Django's Model.save() save only the dirty fields by default?
And how can I do that if I want?
-+-
 Reporter:  prajnamort   |Owner:  nobody
 Type:  Uncategorized|   Status:  closed
Component:  Database layer   |  Version:  1.8
  (models, ORM)  |
 Severity:  Normal   |   Resolution:  invalid
 Keywords:   | Triage Stage:
 |  Unreviewed
Has patch:  0|  Needs documentation:  0
  Needs tests:  0|  Patch needs improvement:  0
Easy pickings:  0|UI/UX:  0
-+-

Comment (by Andreas Bergström):

 There is the django-dirtyfields that will at least tell you if a model is
 dirty and what fields that's dirty, but it won't do the saving...
 https://github.com/romgar/django-dirtyfields

-- 
Ticket URL: 
Django 
The Web framework for perfectionists with deadlines.

-- 
You received this message because you are subscribed to the Google Groups 
"Django updates" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to django-updates+unsubscr...@googlegroups.com.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/django-updates/068.cd446c4cac6854a749f3704bc1d8ff81%40djangoproject.com.


Re: [Django] #27017: Why doesn't Django's Model.save() save only the dirty fields by default? And how can I do that if I want?

2019-01-26 Thread Django
#27017: Why doesn't Django's Model.save() save only the dirty fields by default?
And how can I do that if I want?
-+-
 Reporter:  prajnamort   |Owner:  nobody
 Type:  Uncategorized|   Status:  closed
Component:  Database layer   |  Version:  1.8
  (models, ORM)  |
 Severity:  Normal   |   Resolution:  invalid
 Keywords:   | Triage Stage:
 |  Unreviewed
Has patch:  0|  Needs documentation:  0
  Needs tests:  0|  Patch needs improvement:  0
Easy pickings:  0|UI/UX:  0
-+-

Comment (by Tim Graham):

 There's discussion in #4102 about trying to save only dirty fields. It
 looks like there were too many complications. If you want to try to tackle
 this, you should make your proposal on the DevelopersMailingList.

-- 
Ticket URL: 
Django 
The Web framework for perfectionists with deadlines.

-- 
You received this message because you are subscribed to the Google Groups 
"Django updates" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to django-updates+unsubscr...@googlegroups.com.
To post to this group, send email to django-updates@googlegroups.com.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/django-updates/068.4aa727972ddc032fff394cab8b3bfa4d%40djangoproject.com.
For more options, visit https://groups.google.com/d/optout.


Re: [Django] #27017: Why doesn't Django's Model.save() save only the dirty fields by default? And how can I do that if I want?

2019-01-26 Thread Django
#27017: Why doesn't Django's Model.save() save only the dirty fields by default?
And how can I do that if I want?
-+-
 Reporter:  prajnamort   |Owner:  nobody
 Type:  Uncategorized|   Status:  closed
Component:  Database layer   |  Version:  1.8
  (models, ORM)  |
 Severity:  Normal   |   Resolution:  invalid
 Keywords:   | Triage Stage:
 |  Unreviewed
Has patch:  0|  Needs documentation:  0
  Needs tests:  0|  Patch needs improvement:  0
Easy pickings:  0|UI/UX:  0
-+-
Changes (by Dan Tao):

 * cc: Dan Tao (added)


Comment:

 Can I make a case for re-opening this?

 I understand that `update_fields` makes it possible to only update
 specific fields of a model. But it places a significant burden on calling
 code and introduces a maintenance cost. For me to explain, first consider
 a typical function where `update_fields` can be useful:

 {{{
 def update_thing(pk, foo):
 thing = Thing.objects.get(pk=pk)
 thing.foo = foo
 thing.save()
 }}}

 Code like this is incredibly common but potentially problematic,
 especially for sites with heavy production traffic. Different processes
 running to update various fields on the same model at the same time are
 prone to clobber each other's writes. This is where `update_fields` is
 currently the best fix available:

 {{{
 def update_thing(pk, foo):
 thing = Thing.objects.get(pk=pk)
 thing.foo = foo
 thing.save(update_fields=['foo'])
 }}}

 I see two ways this could be better. First, this solution requires calling
 code to define the same information twice (what field(s) to update).
 Second, it adds a maintenance tax, as any developer who sets another field
 in the future has to remember to also update `update_fields`:

 {{{
 def update_thing(pk, foo, bar):
 thing = Thing.objects.get(pk=pk)
 thing.foo = foo
 thing.bar = bar
 thing.save(update_fields=['foo', 'bar'])
 }}}

 The above example is contrived, of course; most real-world functions are
 bigger and more complex than this, meaning the opportunity to make
 mistakes is typically greater.

 In my opinion Django could make most code bases inherently more resilient
 against latent race conditions by implementing some form of dirty field
 tracking and effectively providing the functionality of `update_fields`
 automatically. I would like to propose a new setting, something like
 `SAVE_UPDATE_DIRTY_FIELDS_ONLY`, to change the ORM's default behavior so
 that calls to `Model.save()` only update the fields that have been set on
 the model instance. Naturally for backwards compatibility this setting
 would be `False` by default.

 I admit I probably haven't thought through all of the scenarios in which
 this might not be desirable. But my intuition is that more often than not,
 this change would be a very good one. Off the top of my head, some
 necessary exceptions to this behavior include:

 - Calling `save()` on a new model instance without a PK (when inserting a
 record for the first time we obviously want to save all fields' default
 values)
 - Fields that are designed to be set automatically, e.g.
 `DateTimeField(auto_now=True)`
 - Any calls to `save()` where `update_fields` has been explicitly
 specified should remain untouched, I would think

 If I'm making sense here, and there is support for re-opening this,
 perhaps it would make sense to update the title of this ticket to sound
 more like a feature request since I realize it currently reads like a
 usage question.

-- 
Ticket URL: 
Django 
The Web framework for perfectionists with deadlines.

-- 
You received this message because you are subscribed to the Google Groups 
"Django updates" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to django-updates+unsubscr...@googlegroups.com.
To post to this group, send email to django-updates@googlegroups.com.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/django-updates/068.d87a1954236d60fc59f2bfedb2350dd1%40djangoproject.com.
For more options, visit https://groups.google.com/d/optout.


Re: [Django] #27017: Why doesn't Django's Model.save() save only the dirty fields by default? And how can I do that if I want?

2016-08-04 Thread Django
#27017: Why doesn't Django's Model.save() save only the dirty fields by default?
And how can I do that if I want?
-+-
 Reporter:  prajnamort   |Owner:  nobody
 Type:  Uncategorized|   Status:  closed
Component:  Database layer   |  Version:  1.8
  (models, ORM)  |
 Severity:  Normal   |   Resolution:  invalid
 Keywords:   | Triage Stage:
 |  Unreviewed
Has patch:  0|  Needs documentation:  0
  Needs tests:  0|  Patch needs improvement:  0
Easy pickings:  0|UI/UX:  0
-+-
Changes (by timgraham):

 * status:  new => closed
 * resolution:   => invalid


Comment:

 Please see TicketClosingReasons/UseSupportChannels for places to ask usage
 questions.

--
Ticket URL: 
Django 
The Web framework for perfectionists with deadlines.

-- 
You received this message because you are subscribed to the Google Groups 
"Django updates" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to django-updates+unsubscr...@googlegroups.com.
To post to this group, send email to django-updates@googlegroups.com.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/django-updates/068.2efc3b5a330e18ba9a6abb23e035538f%40djangoproject.com.
For more options, visit https://groups.google.com/d/optout.


Re: [Django] #27017: Why doesn't Django's Model.save() save only the dirty fields by default? And how can I do that if I want?

2016-08-04 Thread Django
#27017: Why doesn't Django's Model.save() save only the dirty fields by default?
And how can I do that if I want?
-+-
 Reporter:  prajnamort   |Owner:  nobody
 Type:  Uncategorized|   Status:  new
Component:  Database layer   |  Version:  1.8
  (models, ORM)  |
 Severity:  Normal   |   Resolution:
 Keywords:   | Triage Stage:
 |  Unreviewed
Has patch:  0|  Needs documentation:  0
  Needs tests:  0|  Patch needs improvement:  0
Easy pickings:  0|UI/UX:  0
-+-
Changes (by Gwildor):

 * needs_better_patch:   => 0
 * needs_tests:   => 0
 * needs_docs:   => 0


Comment:

 You can manually pass `update_fields` to the `save()` method. Only the
 fields in that list will be updated through the query. See the docs:
 https://docs.djangoproject.com/en/1.9/ref/models/instances/#specifying-
 which-fields-to-save

--
Ticket URL: 
Django 
The Web framework for perfectionists with deadlines.

-- 
You received this message because you are subscribed to the Google Groups 
"Django updates" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to django-updates+unsubscr...@googlegroups.com.
To post to this group, send email to django-updates@googlegroups.com.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/django-updates/068.71116be086c65e20c5f07b828a053276%40djangoproject.com.
For more options, visit https://groups.google.com/d/optout.


[Django] #27017: Why doesn't Django's Model.save() save only the dirty fields by default? And how can I do that if I want?

2016-08-04 Thread Django
#27017: Why doesn't Django's Model.save() save only the dirty fields by default?
And how can I do that if I want?
--+
 Reporter:  prajnamort|  Owner:  nobody
 Type:  Uncategorized | Status:  new
Component:  Database layer (models, ORM)  |Version:  1.8
 Severity:  Normal|   Keywords:
 Triage Stage:  Unreviewed|  Has patch:  0
Easy pickings:  0 |  UI/UX:  0
--+
 I've noticed that Model.save() will update all fields by default, which
 can introduce a lot of race conditions.
 If it update only the dirty fields, the situation would be much better.
 How can I do that?

--
Ticket URL: 
Django 
The Web framework for perfectionists with deadlines.

-- 
You received this message because you are subscribed to the Google Groups 
"Django updates" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to django-updates+unsubscr...@googlegroups.com.
To post to this group, send email to django-updates@googlegroups.com.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/django-updates/053.d28361e008142880a68cd6afa2024707%40djangoproject.com.
For more options, visit https://groups.google.com/d/optout.