Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Integrity Error on delete #19

Open
ashiazed opened this issue Jun 21, 2013 · 5 comments
Open

Integrity Error on delete #19

ashiazed opened this issue Jun 21, 2013 · 5 comments

Comments

@ashiazed
Copy link

I've come across an issue where I can't delete an object with a placeholder field.

update or delete on table "fluent_contents_placeholder" violates foreign key constraint "placeholder_id_refs_id_8e1f1b78" on table "fluent_contents_contentitem"
DETAIL: Key (id)=(9) is still referenced from table "fluent_contents_contentitem".

It seems like the delete doesn't cascade properly to the fluent_contents_contentitem.

using django 1.5.1
latest fluent-contents via git

Let me know what other information I need to provide.

@vdboor
Copy link
Contributor

vdboor commented Jun 24, 2013

Thanks, this is really helpful to know!

There are a few things I'm curious about:

  • Do you happen to have a stack trace, or a way to reproduce this issue? (e.g. some example code, or what steps to take?)
  • Do your users have superuser permission, or are their permissions restricted to certain models?

@ashiazed
Copy link
Author

Sure thing. Here are the details of a minimal app that renders the error message in admin.
One thing to note is that the error only comes up when there is a combination of the two plugins, that is at least one of each.
User is superuser.
Database is brand new.

Stacktrace

Environment:


Request Method: POST
Request URL: http://localhost:8000/admin/stuff/stuff/

Django Version: 1.5.1
Python Version: 2.7.4
Installed Applications:
('suit',
 'django.contrib.auth',
 'django.contrib.contenttypes',
 'django.contrib.sessions',
 'django.contrib.sites',
 'django.contrib.messages',
 'django.contrib.staticfiles',
 'django.contrib.admin',
 'south',
 'fluent_contents',
 'fluent_contents.plugins.text',
 'django_wysiwyg',
 'markupfield',
 'filer',
 'mptt',
 'easy_thumbnails',
 'autoslug',
 'simple_contact',
 'core',
 'brands',
 'brands.plugins',
 'stuff',
 'stuff.plugins',
 'debug_toolbar',
 'debug_toolbar',
 'discover_runner',
 'functional_tests')
Installed Middleware:
('django.middleware.common.CommonMiddleware',
 'django.contrib.sessions.middleware.SessionMiddleware',
 'django.middleware.csrf.CsrfViewMiddleware',
 'django.contrib.auth.middleware.AuthenticationMiddleware',
 'django.contrib.messages.middleware.MessageMiddleware',
 'debug_toolbar.middleware.DebugToolbarMiddleware')


Traceback:
File "/home/ashia/virtualenvs/identity/local/lib/python2.7/site-packages/django/core/handlers/base.py" in get_response
  115.                         response = callback(request, *callback_args, **callback_kwargs)
File "/home/ashia/virtualenvs/identity/local/lib/python2.7/site-packages/django/contrib/admin/options.py" in wrapper
  372.                 return self.admin_site.admin_view(view)(*args, **kwargs)
File "/home/ashia/virtualenvs/identity/local/lib/python2.7/site-packages/django/utils/decorators.py" in _wrapped_view
  91.                     response = view_func(request, *args, **kwargs)
File "/home/ashia/virtualenvs/identity/local/lib/python2.7/site-packages/django/views/decorators/cache.py" in _wrapped_view_func
  89.         response = view_func(request, *args, **kwargs)
File "/home/ashia/virtualenvs/identity/local/lib/python2.7/site-packages/django/contrib/admin/sites.py" in inner
  202.             return view(request, *args, **kwargs)
File "/home/ashia/virtualenvs/identity/local/lib/python2.7/site-packages/django/utils/decorators.py" in _wrapper
  25.             return bound_func(*args, **kwargs)
File "/home/ashia/virtualenvs/identity/local/lib/python2.7/site-packages/django/utils/decorators.py" in _wrapped_view
  91.                     response = view_func(request, *args, **kwargs)
File "/home/ashia/virtualenvs/identity/local/lib/python2.7/site-packages/django/utils/decorators.py" in bound_func
  21.                 return func(self, *args2, **kwargs2)
File "/home/ashia/virtualenvs/identity/local/lib/python2.7/site-packages/django/contrib/admin/options.py" in changelist_view
  1221.                 response = self.response_action(request, queryset=cl.get_query_set(request))
File "/home/ashia/virtualenvs/identity/local/lib/python2.7/site-packages/django/contrib/admin/options.py" in response_action
  960.             response = func(self, request, queryset)
File "/home/ashia/virtualenvs/identity/local/lib/python2.7/site-packages/django/contrib/admin/actions.py" in delete_selected
  47.             queryset.delete()
File "/home/ashia/virtualenvs/identity/local/lib/python2.7/site-packages/django/db/models/query.py" in delete
  537.         collector.delete()
File "/home/ashia/virtualenvs/identity/local/lib/python2.7/site-packages/django/db/models/deletion.py" in decorated
  64.                 transaction.commit(using=self.using)
File "/home/ashia/virtualenvs/identity/local/lib/python2.7/site-packages/django/db/transaction.py" in commit
  152.     connection.commit()
File "/home/ashia/virtualenvs/identity/local/lib/python2.7/site-packages/django/db/backends/__init__.py" in commit
  241.         self._commit()
File "/home/ashia/virtualenvs/identity/local/lib/python2.7/site-packages/django/db/backends/postgresql_psycopg2/base.py" in _commit
  242.                 six.reraise(utils.IntegrityError, utils.IntegrityError(*tuple(e.args)), sys.exc_info()[2])
File "/home/ashia/virtualenvs/identity/local/lib/python2.7/site-packages/django/db/backends/postgresql_psycopg2/base.py" in _commit
  240.                 return self.connection.commit()

Exception Type: IntegrityError at /admin/stuff/stuff/
Exception Value: update or delete on table "fluent_contents_placeholder" violates foreign key constraint "placeholder_id_refs_id_8e1f1b78" on table "fluent_contents_contentitem"
DETAIL:  Key (id)=(1) is still referenced from table "fluent_contents_contentitem".

Model

class Stuff(models.Model):
    title = models.CharField(max_length=255)
    content = PlaceholderField("stuff_content")

    def __unicode__(self):
        return self.title

Plugin model

class ContentBlock(ContentItem):
    """
    Simple text block with title
    """
    title = models.CharField(_("Title"), max_length=255)
    body = models.TextField()

    class Meta:
        verbose_name=_("Content stuff")
        verbose_name_plural = _("Content stuff")

    def __unicode__(self):
        return self.title


class TwoColumnBlock(ContentItem):
    """
    Two column block
    """
    left_columns = models.TextField()
    right_columns  = models.TextField()

    class Meta:
        verbose_name=_("Two Column stuff")
        verbose_name_plural = _("Two Column stuff")

    def __unicode__(self):
        return self.left_columns

Plugin content plugins

@plugin_pool.register
class ContentBlockPlugin(ContentPlugin):
    model = ContentBlock
    render_template = "plugins/contentblock.html"


@plugin_pool.register
class TwoColumnBlockPlugin(ContentPlugin):
    model = TwoColumnBlock
    render_template = "plugins/twocolumnblock.html"

@vdboor
Copy link
Contributor

vdboor commented Oct 3, 2013

Sorry for not getting back to you, I completely missed your message. I'll try to see whether I can fix this.

As workaround, try adding the ContentItemRelation to your Stuff model:

from fluent_contents.models import ContentItemRelation

class Stuff(models.Model):
    title = models.CharField(max_length=255)
    content = PlaceholderField("stuff_content")
    contentitem_set = ContentItemRelation()

This change causes the admin delete view and "collector object" to detect those contentitems which are attached to your model. I'll see if I can make this happen automatically.

@jpotterm
Copy link
Contributor

jpotterm commented Nov 8, 2013

I've run into this problem also, and I came up with the same workaround that you mention. It's been working for me. It would be nice if you could fix this in the plugin though!

@RealBigB
Copy link

Same problem with fluent_pages.pagetypes.fluentpages, cf django-fluent/django-fluent-pages#57

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

4 participants