Hello, first, let me give you an idea of the problem I'm facing. This is a 
company with a fruit packaging plant, they use several printers for the 
barcodes they attach in fruit boxes, clamshells and pallets. There is a 
Django table that keeps track of the current number for each one (caja, 
clamshell and pallet):

<https://lh3.googleusercontent.com/-dmAawvjfCg4/ViZuR_tPlvI/AAAAAAAAY08/zD0pPBWATeE/s1600/series.png>

They don't want to be holes in the middle, if the current number for a box is 
*00071799* then there must be boxes from *00000001 *to *00071798*.  These 
numbers are used as primary keys for the Caja, Clamshell and Pallet models. 

The printing process is using atomic transactions:

@transaction.atomic
def print_barcodes(request):
    tid = transaction.savepoint()
    # lot of code here
    if error:
       transaction.savepoint_rollback(tid)
    # ...
    return JsonResponse(response)
 

We are getting a lot of these:

_mysql_exceptions.IntegrityError: (1062, "Duplicate entry 'XXXXXXXXXX' for 
key 'PRIMARY'")

Which means we have a fault in the process or maybe we are improperly using 
transactions. Help will be much appreciated regarding the problem and the 
following questions:

   1. If we print 10 boxes from *00000001 *to *00000010* and say 
   (exaggeratedly) each box takes 1 second to print. Then, another guy wants 
   to print boxes while the first transaction is still active, will he get  
   *00000011*? Considering that the numbers are updated during the 
   transaction.
   2. Do transactions stack and lock the tables? 

Thanks a lot





-- 
You received this message because you are subscribed to the Google Groups 
"Django users" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to django-users+unsubscr...@googlegroups.com.
To post to this group, send email to django-users@googlegroups.com.
Visit this group at http://groups.google.com/group/django-users.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/django-users/df8f520b-06ae-4627-88a5-1b51c607052b%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

Reply via email to