title: Why is SQLAlchemy adding more rows than class instances in my program?
body: <p>I have a class <code>GeneList</code> which is a list of <code>Gene</code> instances and another class <code>GeneSignature</code> which is a <code>GeneList</code> plus metadata. For some reason, the number of genes in my gene list changes <em>after</em> I add and commit the list to the database. For example:</p>
  
  <pre><code>print(len(gene_signature.gene_list)) # 204
  session.add(gene_signature)
  session.commit()
  print(len(gene_signature.gene_list)) # 362
  </code></pre>
  
  <p>Oddly enough, this only happens when I'm connected to my development database, which does not have foreign key constraints setup. If I perform the same <code>add</code>/<code>commit</code> with the same input data but connected to my production database with proper foreign key constraints, the numbers are <code>204</code> and then <code>204</code>, as expected.</p>
  
  <p>I thought that foreign key constraints are only for data integrity. What could possibly cause this?</p>
  
  <p><strong>EDIT:</strong></p>
  
  <p>I've setup foreign keys and the problem resolved itself. Why?</p>