title: Assuming a many to many relationship model in sqlalchemy with mysql, how to update data ignoring duplicates?
body: <p>I am a little stuck with sqlalchemy trying to update some data.</p>
  
  <p>I have a <em>many to many</em> and a <em>one to many</em> relationship. The first is a relationship between an author and the possible spellings of his name. The second is linking authors to their written literature. A paper may have several authors and vice versa.</p>
  
  <p>Assuming an author "Peter Shaw" who has already 4 papers stored and linked to him in the database. No I want to "add" a new set of 6 papers for "Peter Shaw". Unfortunately 4 of the 6 papers are already stored in the database. This is why <code>session.commit()</code> results in a duplicate error.</p>
  
  <p>Is there a common way to avoid the duplicate errors, and to tell sqlalchemy to just fill in the holes instead of complaining about the duplicates? Neither the docus of sqlalchemy nor google could enlighten me with an explicit answer/approach, so any suggestions are well apreciated.</p>
  
  <p>These are the models I am testing with:</p>
  
  <pre><code>class NameSpelling(Base):
      __tablename__ = 'name_spellings'
  
      id = Column(Integer, primary_key=True)
      name = Column(String(255), nullable=False, unique=True, index=True)
      authors_id = Column(Integer, ForeignKey('authors.id'))
  
      def __init__(self, name=None):
          self.name = name
  
      def __repr__(self):
          return "NameSpelling(%r)" % (self.name)
  
  class Author(Base):
      __tablename__ = 'authors'
  
      id = Column(Integer, primary_key=True)
      name = Column(String(255), nullable=True, unique=True, index=True)
  
      papers = relationship('Paper',
                            secondary=author_paper,
                            backref='authors')
  
      name_spellings = relationship(NameSpelling,
                                    order_by=NameSpelling.id,
                                    backref="author",
                                    cascade="all, delete, delete-orphan")
  
      def __init__(self, name=None):
          self.name = name
  
      def __repr__(self):
          return "Authors(%r, %r)" % (self.name_spellings, self.name)
  
  
  class Paper(Base):
      __tablename__ = 'papers'
  
      id = Column(Integer, primary_key=True)
      title = Column(String(1500), nullable=False, index=True)
      url = Column(String(255), nullable=False, unique=True, index=True)
      date = Column(Date(), nullable=True)
  
      def __init__(self, title=None, url=None, date=None):
          self.title = title
          self.url = url
          self.date = date
  
      def __repr__(self):
          return "Paper(%r)" % (self.title)
  </code></pre>