title: Conflicting bind parameters in SQLAlchemy when using SQLite
body: <p>I use a SQLite in-memory database for running unit tests, and a psql for production environments. In sqlite, I see the following issue:
  <code>sqlalchemy.exc.CompileError: Bind parameter '%(139849590720976 type)s' conflicts with unique bind parameter of the same name</code></p>
  <p>I've tried finding out what this means but Google hasn't helped me so far. I'm using
  polymorphic identities on the table I'm querying:</p>
  <pre class="lang-py prettyprint-override"><code>def get_display_units(id, verified_only=True):
      subq = (
          db.session.query(
              Foo.hash,
              func.max(Foo.version).label(&quot;max_version&quot;),
          )
          .filter(
              Foo.instance_id == id,
          )
          .group_by(Foo.hash)
          .subquery(&quot;sub&quot;)
      )
  
      filters = [
          Foo.instance_id == id,
          Foo.deleted.isnot(True),
          Foo.version == subq.c.max_version,
          Foo.hash == subq.c.hash,
      ]
  
      if verified_only:
          filters.append(Foo.approver_id.isnot(None))
      query = db.session.query(Foo).join(subq, and_(*filters))
      return query.all()
  
  </code></pre>
  <p>A print of the (sub)query yields the following:</p>
  <pre class="lang-sql prettyprint-override"><code>SELECT foo.train, max(foo.version) AS max_version 
  FROM foo 
  WHERE foo.instance_id = :instance_id_1 AND foo.type IN ([POSTCOMPILE_type_1]) GROUP BY foo.train
  </code></pre>
  <p>But a print of the joined statement already throws the error :/</p>
  <p>It seems as if the IN statement is what's breaking my code (see <a href="https://docs.sqlalchemy.org/en/14/faq/sqlexpressions.html#rendering-postcompile-parameters-as-bound-parameters" rel="nofollow noreferrer">https://docs.sqlalchemy.org/en/14/faq/sqlexpressions.html#rendering-postcompile-parameters-as-bound-parameters</a>)</p>
  <p>Please note, i'm using a Single table inheritance model for the <code>Foo</code> model (see <a href="https://docs.sqlalchemy.org/en/14/orm/inheritance.html#single-table-inheritance" rel="nofollow noreferrer">https://docs.sqlalchemy.org/en/14/orm/inheritance.html#single-table-inheritance</a>) which is why there's a <code>.type</code> parameter in the query.</p>
  <p>Any idea on how to solve this?</p>