Changes between Initial Version and Version 1 of Ticket #36489


Ignore:
Timestamp:
Jun 30, 2025, 4:23:42 PM (2 months ago)
Author:
Brian Atkinson
Comment:

Legend:

Unmodified
Added
Removed
Modified
  • Ticket #36489 – Description

    initial v1  
    1313}}}
    1414
    15 In effect, we have two separate processes both expecting to be able to call `Child.objects.get_or_create(parent=common_parent, defaults={...})` and have the resulting `common_parent.child` be the correct result. We are seeing both processes fail the initial get call (https://github.com/django/django/blob/ff0ff98d427982b7225df59f454a86bdf66251d6/django/db/models/query.py#L977) and proceeding to attempt the create call (https://github.com/django/django/blob/ff0ff98d427982b7225df59f454a86bdf66251d6/django/db/models/query.py#L984). One of the processes succeeds on the insert, and the other will fail the insert. The process that fails the insert correctly issues the second get call (https://github.com/django/django/blob/ff0ff98d427982b7225df59f454a86bdf66251d6/django/db/models/query.py#L987) and returns the result.
     15In effect, we have two separate processes both expecting to be able to call `Child.objects.get_or_create(parent=common_parent, defaults={...})` and have the resulting `common_parent.child` be the correct result. We are seeing both processes fail the initial get call (https://github.com/django/django/blob/5.2.3/django/db/models/query.py#L946) and proceeding to attempt the create call (https://github.com/django/django/blob/5.2.3/django/db/models/query.py#L953). One of the processes succeeds on the insert, and the other will fail the insert. The process that fails the insert correctly issues the second get call (https://github.com/django/django/blob/5.2.3/django/db/models/query.py#L956) and returns the result.
    1616
    1717The bug is that for the process that fails the insert, the object at `common_parent.child` is not the value returned from the get_or_create. It seems to be the object that was created for insert, but wasn't cleared when the insert failed. This can be observed through the `common_parent.child.id` field being None. This has caused data corruption and other downstream bugs due to the wrong data being cached.
Back to Top