title: Duplicate request threads create duplicate database entries in Django model
body: <p><strong>The problem</strong>: a signal receiver checks to see if a model entry exists for certain conditions, and if not, it creates a new entry. In some rare circumstances, the entry is being duplicated. </p>
  
  <p>Within the receiver function:</p>
  
  <pre><code>try:
      my_instance = MyModel.objects.get(field1=value1, field2=sender)
  except:
      my_instance = MyModel(field1=value1, field2=sender)
      my_instance.save()
  </code></pre>
  
  <p>It's an obvious candidate for <code>get_or_create</code>, but aside from cleaning up that code, would using <code>get_or_create</code> help prevent this problem?</p>
  
  <p>The signal is sent after a user action, but I don't believe that the originating request is being duplicated because that would have trigged other actions. </p>
  
  <p>The duplication has occurred a few times in thousands of instances. Is this necessarily caused by multiple requests or is there some way a duplicate thread could be created? And is there a way - perhaps with granular transaction management - to prevent the duplication?</p>
  
  <p>Using Django 1.1, Python 2.4, PostgreSQL 8.1, and mod_wsgi on Apache2. </p>