Is it bad practice to rely on db exceptions to indicate an attempt at writing duplicate values to a "keyed" column? For example, in some code I'm working on, I have the following:
x = ContentItem(title=e_title) try: x.save() except MySQLError: x = ContentItem.objects.get(title=e_title) for tag_title in tag_titles: y = Tag(title=tag_title) try: y.save() except MySQLError: y = Tag.objects.get(title=e_title) x.tags.add(y) Catching the MySQLError indicates to me that that title already exists in the db, so I then retrieve it instead of inserting it. I have a feeling that some folks will say this is bad, but if so, I'm curious why. To me, it seems better than significantly increasing the # of queries I have to run to check if the data's already there before I write it. Thanks for any help. --~--~---------~--~----~------------~-------~--~----~ 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 django-users+unsubscr...@googlegroups.com For more options, visit this group at http://groups.google.com/group/django-users?hl=en -~----------~----~----~----~------~----~------~--~---