#21705 closed Bug (invalid)

Generic Relations fail to detect validation error appropritely

Reported by: mo_ttds@… Owned by: nobody
Component: contrib.admin Version: 1.6
Severity: Normal Keywords: AdminSite, GenericRelation, unique_together, IntegrityError
Cc: Triage Stage: Unreviewed
Has patch: no Needs documentation: no
Needs tests: no Patch needs improvement: no
Easy pickings: no UI/UX: no

Description

Hi. When using a GenericRelation on a Model to create a M2M generic relation between two other models, with a unique_together attribute on the relation. admin site fails to detect uniqueness-validation and instead of reporting a unique violation validation error it raises an IntegrityError e.g. IntegrityError: columns tag_id, object_id are not unique

here is the case:

class Tag(models.Model):
    slug = models.SlugField(max_length=100)
    
    def __unicode__(self):
        return self.slug

class News(models.Model):
    title = models.CharField(max_length=100)
    
    def __unicode__(self):
        return self.title
    
class Tagger(models.Model):
    class Meta:
        '''unique_together = ('tag', 'object_id')'''
    
    tag = models.ForeignKey(Tag)
    content_type    = models.ForeignKey(ContentType)
    object_id       = models.PositiveIntegerField()
    content_object  = generic.GenericForeignKey()

and creating the admin objects like this:

class TagAdmin(admin.ModelAdmin):
    list_display = ('slug',)

class TabularTagInline(generic.GenericTabularInline):
    model = models.Tagger
    extra = 2

class NewsAdmin(admin.ModelAdmin):
    list_display = ('title', )
    inlines = (TabularTagInline,)

admin.site.register(Blog, BlogAdmin)
admin.site.register(Tag, TagAdmin)

Change History (3)

comment:1 Changed 16 months ago by anonymous

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

admin.site.register(Blog, BlogAdmin) should be admin.site.register(News, BlogAdmin).

comment:2 Changed 16 months ago by anonymous

sorry.
admin.site.register(Blog, BlogAdmin) should be admin.site.register(News, NewsAdmin).

comment:3 Changed 16 months ago by mo_ttds...

  • Resolution set to invalid
  • Status changed from new to closed
Note: See TracTickets for help on using tickets.
Back to Top