Code

Opened 3 years ago

Closed 3 years ago

#16587 closed Bug (invalid)

get_or_create duplicate entry with together_unique

Reported by: lazzaroleonardo@… Owned by: nobody
Component: Database layer (models, ORM) Version: master
Severity: Normal Keywords:
Cc: Triage Stage: Unreviewed
Has patch: no Needs documentation: no
Needs tests: no Patch needs improvement: no
Easy pickings: no UI/UX: no

Description

model example

class Example(Stat):

numeric = models.IntegerField(...)
date = models.DateField(...)


class Meta:

unique_together = ('name','date')

If 'john' and '2011-6-8' is already stored

Example.object.get_or_create(name='john',date='2011-6-8')

raises django.db.utils.IntegrityError: (1062, "Duplicate entry '72-2011-08-07'

Attachments (0)

Change History (3)

comment:1 Changed 3 years ago by llazzaro

  • Needs documentation unset
  • Needs tests unset
  • Patch needs improvement unset

Sorry this is the right description

model example

class Example(Stat):
    numeric = models.IntegerField(...) 
    date = models.DateField(...)

    class Meta:
       unique_together = ('numeric','date')

Suppose 72 and '2011-08-07' is already stored

this code :

Example.object.get_or_create(numeric=72,date='2011-08-07')

Raises

django.db.utils.IntegrityError: (1062, "Duplicate entry '72-2011-08-07'
Last edited 3 years ago by llazzaro (previous) (diff)

comment:2 Changed 3 years ago by aaugustin

Does this work?

import datetime
Example.object.get_or_create(numeric=72, date=datetime.date(2011, 8, 7))

comment:3 Changed 3 years ago by llazzaro

  • Resolution set to invalid
  • Status changed from new to closed

the problemas was with auto_now_add=True in DateField

Add Comment

Modify Ticket

Change Properties
<Author field>
Action
as closed
as The resolution will be set. Next status will be 'closed'
The resolution will be deleted. Next status will be 'new'
Author


E-mail address and user name can be saved in the Preferences.

 
Note: See TracTickets for help on using tickets.