title: Compare A Python List To A SQLAlchemy Collection
body: <p><strong>How do I compare a Python list to a SQLAlchemy collection?</strong></p>
  
  <p>I get the following error message</p>
  
  <pre><code>InvalidRequestError: Can't compare a collection to an object or collection; use contains() to test for membership
  </code></pre>
  
  <p>from this line</p>
  
  <pre><code>gr = AGroup.query.filter_by(users=sorted(members)).first()
  </code></pre>
  
  <p>Members is a list of AUser objects. </p>
  
  <p>I want to check if any group exists with the same users as the members list.</p>
  
  <p>However, since users is an sqlalchemy collection, this is not working. </p>
  
  <p>Thank you. :)</p>
  
  <p>Basic Class Structure</p>
  
  <pre><code>AGroup
  - users
  
  AUser
  - name
  </code></pre>