#30375: Use "NO KEY" when doing select_for_update for PostgreSQL
-------------------------------------+-------------------------------------
     Reporter:  Manuel Weitzman      |                    Owner:  nobody
         Type:                       |                   Status:  new
  Cleanup/optimization               |
    Component:  Database layer       |                  Version:  master
  (models, ORM)                      |
     Severity:  Normal               |               Resolution:
     Keywords:  postgres, lock,      |             Triage Stage:
  database, operation                |  Unreviewed
    Has patch:  1                    |      Needs documentation:  0
  Needs tests:  0                    |  Patch needs improvement:  0
Easy pickings:  0                    |                    UI/UX:  0
-------------------------------------+-------------------------------------

Comment (by Manuel Weitzman):

 Replying to [comment:2 Simon Charette]:
 > > ... in Django, primary key fields are read-only, so locking them makes
 no sense
 >
 > That's not true AFAIK. Even if `AutoField` are backed by sequences and
 generated on the database side they can still be overridden by developers.
 Same thing with non-`AutoField` primary keys (e.g.
 `UUIDField(default=uuid.uuid4)`).

 Then the docs are wrong or at least misleading: ''"The primary key field
 is read-only. If you change the value of the primary key on an existing
 object and then save it, a new object will be created alongside the old
 one."" (https://docs.djangoproject.com/en/2.2/topics/db/models/)

 Which means that UPDATEs over PKs are transformed into INSERTs

 > On the other hand updating a primary key while holding a lock is really
 uncommon so I wouldn't be against adding a `select_for_udate(primary_key)`
 parameter that defaults to `False`. We just have to make sure that we
 still allow these operations to be performed somehow.

 That is possible, I tested today and only a few changes are required to
 achieve this behavior. Maybe I could send a PR soon for review?

-- 
Ticket URL: <https://code.djangoproject.com/ticket/30375#comment:3>
Django <https://code.djangoproject.com/>
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/064.783c6ff1398863c7349397b7c7af8e4e%40djangoproject.com.
For more options, visit https://groups.google.com/d/optout.

Reply via email to