Michael Radziej wrote: > That's a good spot. > > It's hard to impossible to catch the error and figure out what the > error message means, since there's no real standard how these error > messages look like. All you got is a string ... > > One way to do this is to lock the table Post before validation > starts (and unlock with the end of the transaction). There's no real > support for this in the Django ORM (or is there? I'm not 100 % > sure), but you can do it with custom SQL.
Well, that would eliminate the need to catch IntegrityErrors at the cost of slowing down every commit. > The other would be to catch the database error and then validate > again. But in the meantime, something else could have happened, so > you end up with a structure like this: > > for i in range(settings.RETRIES) > ... validate ... > try: > ... save ... > break > except ... > ... roll back ... > > You don't want to loop forever, since it could be an error that is > not related to validation, like that the database is unavailable. The loop is a good idea if you allow deletion/update of rows, in the example I gave before there was an implicit assumption that only inserts were allowed. > Both approaches don't look very appealing if you need to do this for > every form. The generic views don't (I think). Perhaps there should > be some support for this. If we can find a way to deal with this in > a generic way, that could be added to Django. Adding generic support for this would be a bit difficult, because there are different ways to handle it depending on which operations you allow on the underlying table and the likelihood of an IntegrityError occurring, and that's going to differ from form to form. I think a good start would be to actually allow people to catch IntegrityError(s) by making it available through django.db, that way people who want to try and deal with these errors gracefully can do so. -+ enlight +- --~--~---------~--~----~------------~-------~--~----~ You received this message because you are subscribed to the Google Groups "Django users" group. To post to this group, send email to django-users@googlegroups.com To unsubscribe from this group, send email to [EMAIL PROTECTED] For more options, visit this group at http://groups.google.com/group/django-users?hl=en -~----------~----~----~----~------~----~------~--~---