Changes between Initial Version and Version 1 of Ticket #36551


Ignore:
Timestamp:
Aug 14, 2025, 9:31:36 AM (6 weeks ago)
Author:
Natalia Bidart
Comment:

Hello Mijo Kristo, thank you for your ticket report. Can you please confirm:

  • If any part of this report was generated or assisted by an AI/LLM?
  • Does this come from a real-world use case, or is it primarily a theoretical scenario?

This will help us understand and prioritize the issue better.

Legend:

Unmodified
Added
Removed
Modified
  • Ticket #36551

    • Property Easy pickings unset
  • Ticket #36551 – Description

    initial v1  
    66
    77django/db/backends/base/base.py, line ~608
    8 **
    9 Problematic Code**
    108
     9**Problematic Code**
     10{{{
    1111thread_ident = _thread.get_ident()
    1212tid = str(thread_ident).replace("-", "")
     
    1414self.savepoint_state += 1  # Race condition here
    1515sid = "s%s_x%d" % (tid, self.savepoint_state)
     16}}}
    1617
    1718**Impact**
     
    2627
    2728The race condition can be reproduced with this simple test:
    28 
     29{{{#!python
    2930import threading, time
    3031
     
    4344
    4445print(f'Final: {counter} (should be 5)')
     46}}}
    4547
    4648Expected output: Final: 5
     
    5557- Inventory overselling in high-traffic scenarios
    5658
    57 **Proposed Fix
    58 **
     59**Proposed Fix **
     60
    5961Wrap the increment operation in the existing _thread_sharing_lock:
    60 
     62{{{#!python
    6163thread_ident = _thread.get_ident()
    6264tid = str(thread_ident).replace("-", "")
     
    6567    self.savepoint_state += 1
    6668    sid = "s%s_x%d" % (tid, self.savepoint_state)
    67 
     69}}}
    6870This solution:
    6971- Uses Django's existing thread safety infrastructure
Back to Top