Catch database error in registry

This commit is contained in:
David Gelvin 2010-09-08 12:18:29 +00:00
parent 4a889b48bf
commit 9afdc58a05
2 changed files with 7 additions and 15 deletions

View file

@ -83,11 +83,6 @@ class EavAttribute(models.Model):
self.slug = EavSlugField.create_slug_from_name(self.name)
self.full_clean()
super(EavAttribute, self).save(*args, **kwargs)
EavEntity.update_all_caches()
def delete(self, *args, **kwargs):
EavEntity.update_all_caches()
super(EavAttribute, self).delete(*args, **kwargs)
def add_label(self, label):
label, created = EavAttributeLabel.objects.get_or_create(name=label)
@ -259,15 +254,7 @@ class EavEntity(object):
cache['attributes'] = cls.get_eav_attributes().select_related()
cache['slug_mapping'] = dict((s.slug, s) for s in cache['attributes'])
return cache
@classmethod
def update_all_caches(cls):
"""
Update all caches of registered entities.
"""
from .utils import EavRegistry
for entity in EavRegistry.cache.itervalues():
cls.update_attr_cache_for_model(entity['model_cls'])
@classmethod
def flush_attr_cache_for_model(cls, model_cls):

View file

@ -1,4 +1,5 @@
from django.contrib.contenttypes import generic
from django.db.utils import DatabaseError
from django.db.models.signals import post_init, post_save, post_delete
from .managers import EntityManager
from .models import (EavEntity, EavAttribute, EavValue,
@ -86,7 +87,11 @@ class EavRegistry(object):
mgr = EntityManager()
mgr.contribute_to_class(model_cls, config_cls.manager_field_name)
EavEntity.update_attr_cache_for_model(model_cls)
try:
EavEntity.update_attr_cache_for_model(model_cls)
except DatabaseError:
pass
gr_name = config_cls.generic_relation_field_name
generic_relation = generic.GenericRelation(EavValue,