Re: get_or_create gave IntegrityError: (1062, "Duplicate entry) error sometimes
Isn't it because MyISAM does not support transaction? BTW I am using django 1.3.1, mysql 5.5, innodb mysql> SELECT @@GLOBAL.tx_isolation, @@tx_isolation; +---+-+ | @@GLOBAL.tx_isolation | @@tx_isolation | +---+-+ | REPEATABLE-READ | REPEATABLE-READ | +---+-+ another question, does "read committed" affects performance? On 2012/10/16, at 0:35, Tom Evans wrote: > On Mon, Oct 15, 2012 at 3:28 PM, Karen Tracey wrote: >> On Mon, Oct 15, 2012 at 9:43 AM, Tom Evans wrote: >>> >>> On Mon, Oct 15, 2012 at 1:50 PM, Zheng Li wrote: >>>> get_or_create shouldn't give duplicate entry error >>>> anyone help. >>>> >>> >>> This is incorrect, and a common misconception: get_or_create() is not >>> atomic. If this happens, you will get duplicate key errors: >> >> >> No, get_or_create IS intended to be atomic. >> > > I can be intended to be whatever it wants, but since there is no > atomic database operation to get or create a tuple, there is no > guarantee of atomicity. > >>> >>> >>> Thread A calls get_or_create(a='a', b='b') >>> Thread B calls get_or_create(a='a', b='b') >>> Thread A get_or_create looks for entry in DB, not found >>> Thread B get_or_create looks for entry in DB, not found >>> Thread B creates entry in DB >>> Thread A get_or_create tries to create entry in DB >> >> >> Internally, get_or_create code in thread A will now attempt to GET the >> object created by thread B. It will not automatically reflect the error to >> the caller. See: >> >> https://github.com/django/django/blob/stable/1.4.x/django/db/models/query.py#L430 > > I regularly - once every few months - see get_or_create raise > IntegrityError due to duplicate key on MySQL 5.0/MyISAM/Django 1.3. So > whilst that is the intention of the code, it isn't what happens. I'm > happy to blame MySQL. > > Cheers > > Tom > > -- > You received this message because you are subscribed to the Google Groups > "Django users" group. > To post to this group, send email to django-users@googlegroups.com. > To unsubscribe from this group, send email to > django-users+unsubscr...@googlegroups.com. > For more options, visit this group at > http://groups.google.com/group/django-users?hl=en. > -- You received this message because you are subscribed to the Google Groups "Django users" group. To post to this group, send email to django-users@googlegroups.com. To unsubscribe from this group, send email to django-users+unsubscr...@googlegroups.com. For more options, visit this group at http://groups.google.com/group/django-users?hl=en.
Re: get_or_create gave IntegrityError: (1062, "Duplicate entry) error sometimes
get_or_create shouldn't give duplicate entry error anyone help. On 2012/10/13, at 11:06, Wei Wei wrote: > I am new to Django. But does the error message literally mean you have > duplicated records against your unique_together constriction? > > On Sat, Oct 13, 2012 at 9:47 AM, Zheng Li wrote: > class AB(models.Model): > a = models.ForeignKey(A) > b = models.ForeignKey(B) > c = models.IntegerField(default=0) > d = models.FloatField(default=0) > e = models.IntegerField(default=0) > f = models.FloatField(default=0) > class Meta: > unique_together = (('a', 'b'),) > > I have a class like above. > when I call get_or_create, sometimes IntegrityError: (1062, "Duplicate entry) > error happens. > a, _ = AB.objects.get_or_create(a=a, b=b) > > I really have googled and worked on it for a while, but still nothing. > anyone can help? > Thanks in advance. > > -- > You received this message because you are subscribed to the Google Groups > "Django users" group. > To post to this group, send email to django-users@googlegroups.com. > To unsubscribe from this group, send email to > django-users+unsubscr...@googlegroups.com. > For more options, visit this group at > http://groups.google.com/group/django-users?hl=en. > > > -- > You received this message because you are subscribed to the Google Groups > "Django users" group. > To post to this group, send email to django-users@googlegroups.com. > To unsubscribe from this group, send email to > django-users+unsubscr...@googlegroups.com. > For more options, visit this group at > http://groups.google.com/group/django-users?hl=en. -- You received this message because you are subscribed to the Google Groups "Django users" group. To post to this group, send email to django-users@googlegroups.com. To unsubscribe from this group, send email to django-users+unsubscr...@googlegroups.com. For more options, visit this group at http://groups.google.com/group/django-users?hl=en.
get_or_create gave IntegrityError: (1062, "Duplicate entry) error sometimes
class AB(models.Model): a = models.ForeignKey(A) b = models.ForeignKey(B) c = models.IntegerField(default=0) d = models.FloatField(default=0) e = models.IntegerField(default=0) f = models.FloatField(default=0) class Meta: unique_together = (('a', 'b'),) I have a class like above. when I call get_or_create, sometimes IntegrityError: (1062, "Duplicate entry) error happens. a, _ = AB.objects.get_or_create(a=a, b=b) I really have googled and worked on it for a while, but still nothing. anyone can help? Thanks in advance. -- You received this message because you are subscribed to the Google Groups "Django users" group. To post to this group, send email to django-users@googlegroups.com. To unsubscribe from this group, send email to django-users+unsubscr...@googlegroups.com. For more options, visit this group at http://groups.google.com/group/django-users?hl=en.
how to suppress ForeignKey related query
I have a class class PlayerSoul(ModelAbstract, ModelBatchSaveHelper): player = models.ForeignKey(Player) .. When I call PlayerSoul.objects.all() PlayerSoul.objects.get() there is always an additional query for Player. Can I delay the query for Player until I really use it. -- You received this message because you are subscribed to the Google Groups "Django users" group. To post to this group, send email to django-users@googlegroups.com. To unsubscribe from this group, send email to django-users+unsubscr...@googlegroups.com. For more options, visit this group at http://groups.google.com/group/django-users?hl=en.
why can not request context be accessed in filter
if there any reason that request context can NOT be accessed in a filter? -- You received this message because you are subscribed to the Google Groups "Django users" group. To post to this group, send email to django-users@googlegroups.com. To unsubscribe from this group, send email to django-users+unsubscr...@googlegroups.com. For more options, visit this group at http://groups.google.com/group/django-users?hl=en.
Re: question about "\d" in url pattern
thank you very much On 2012/02/28, at 0:37, Justin Myers wrote: > On Feb 27, 1:44 am, Masklinn wrote: >> On 27 févr. 2012, at 07:23, Zheng Li wrote: >>> i thought "\d+" in url promises i can get an int point in cheer_confirm, >>> and am i wrong? >> >> \d+ ensures you will only get naturals, but django will not perform any >> conversion automatically. Especially not here as it would require >> introspecting the regular expression to see which pattern was matched and >> whether it is convertible. > > This is also in the docs: > https://docs.djangoproject.com/en/1.3/topics/http/urls/#notes-on-capturing-text-in-urls > > -- > You received this message because you are subscribed to the Google Groups > "Django users" group. > To post to this group, send email to django-users@googlegroups.com. > To unsubscribe from this group, send email to > django-users+unsubscr...@googlegroups.com. > For more options, visit this group at > http://groups.google.com/group/django-users?hl=en. > -- You received this message because you are subscribed to the Google Groups "Django users" group. To post to this group, send email to django-users@googlegroups.com. To unsubscribe from this group, send email to django-users+unsubscr...@googlegroups.com. For more options, visit this group at http://groups.google.com/group/django-users?hl=en.
question about "\d" in url pattern
url(r'^friend_page/cheer/confirm/(?P\w+)/(?P\d+)/(?P\d+)/$', 'cheer_confirm', name = 'friend_page'), def cheer_confirm(request, fid, key, point): data = { 'point' : 10 + point, } ... i got TypeError: unsupported operand type(s) for +: 'int' and 'unicode' i did "print type(point)", and got type(unicode) apparently, point is not int. i thought "\d+" in url promises i can get an int point in cheer_confirm, and am i wrong? -- You received this message because you are subscribed to the Google Groups "Django users" group. To post to this group, send email to django-users@googlegroups.com. To unsubscribe from this group, send email to django-users+unsubscr...@googlegroups.com. For more options, visit this group at http://groups.google.com/group/django-users?hl=en.
Re: Beginner questions: on the official polls tutorial
Thank you, Shawn. On Wed, Jan 5, 2011 at 8:24 PM, Shawn Milochik wrote: > 1. When you were running the development server, you were probably > executing from the www directory, so importing from 'mysite' would work. > When running in production, it has to be properly on the PYTHONPATH. > I actually was executing from www/mysite, so why it works still seems mysterious to me. > > 2. You need the CSS and stuff for admin available on a server somewhere, > and have your ADMIN_MEDIA_PREFIX in settings.py point to the proper root > URL. > > 3. I don't know that one personally, and I don't use Apache. Someone else > will probably answer. > > Shawn > > -- > You received this message because you are subscribed to the Google Groups > "Django users" group. > To post to this group, send email to django-us...@googlegroups.com. > To unsubscribe from this group, send email to > django-users+unsubscr...@googlegroups.com > . > For more options, visit this group at > http://groups.google.com/group/django-users?hl=en. > > -- You received this message because you are subscribed to the Google Groups "Django users" group. To post to this group, send email to django-us...@googlegroups.com. To unsubscribe from this group, send email to django-users+unsubscr...@googlegroups.com. For more options, visit this group at http://groups.google.com/group/django-users?hl=en.