#26351: get_or_create called twice on a model with CharField and field value over max_length creates 2 objects -------------------------------------+------------------------------------- Reporter: zhebrak | Owner: nobody Type: Bug | Status: new Component: Database layer | Version: 1.9 (models, ORM) | Keywords: get_or_create, Severity: Normal | max_length Triage Stage: Unreviewed | Has patch: 0 Easy pickings: 0 | UI/UX: 0 -------------------------------------+------------------------------------- {{{#!python class Post(models.Model): title = models.CharField(max_length=10)
search_title = 'A' * 11 Post.objects.get_or_create(title=search_title) Post.objects.get_or_create(title=search_title) }}} This code creates two objects because lookup is trying to find non- truncated title and fails to get one so it creates a new object with a truncated title. The second call does exactly the same creating another object. I don't know if it supposed to work this way or not but this behavior seems unclear to me. -- Ticket URL: <https://code.djangoproject.com/ticket/26351> 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/050.e770f10bc4e29e5b249836b1db56584b%40djangoproject.com. For more options, visit https://groups.google.com/d/optout.