Vadim Macagon: > ... > Let's say I have a Post model with a title field, that title must be > unique for a given date. Here's a sequence of events that could > potentially happen: > > time: t1). User A fills in a form to create a new Post, and sets the > title to "Donkeys". > time: t2). User B fills in a form to create a new Post, and sets the > title to "Donkeys". > time: t3). User A submits the form, server validates it to ensure title > is unique and discovers nothing wrong. > time: t3). User B submits the form, server validates it to ensure title > is unique and discovers nothing wrong. > time: t4). Server tries to commit user A's new Post to the db, commit is > successful. > time: t5). Server tries to commit user B's new Post to the db, commit > fails and throws an IntegrityError. > ...
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. 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. 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. Michael -- noris network AG - Deutschherrnstraße 15-19 - D-90429 Nürnberg - Tel +49-911-9352-0 - Fax +49-911-9352-100 http://www.noris.de - The IT-Outsourcing Company --~--~---------~--~----~------------~-------~--~----~ 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 -~----------~----~----~----~------~----~------~--~---