title: SQLAlchemy select with where constraint
body: <p>I am trying to get a subset of a table from my database. The database is a MySql database. </p>
  
  <p>Python code:</p>
  
  <pre><code>from sqlalchemy.ext.declarative import declarative_base
  from sqlalchemy import Column, VARCHAR, DATETIME, INT, TEXT, TIMESTAMP
  from datetime import datetime
  from sqlalchemy.orm import sessionmaker
  
  Base = declarative_base()
  class TrackablesTable(Base):
          __tablename__ = 'Trackables'
  
          trackableId = Column(INT, primary_key=True) #autogenerate
          productID = Column(TEXT)
          createdOn = Column(TIMESTAMP) #autogenerate
          urlTitle = Column(TEXT)
          humanTitle = Column(TEXT)
          userId = Column(VARCHAR(45))
  
  
          def __repr__(self):
                  return "&lt;MyTable(%s)&gt;" % (self.asin)
  
          @staticmethod
          def getTrackableByProductId(productID, session):
              trackable = session.query(TrackablesTable).filter_by(productID=productID)
              return trackable
  </code></pre>
  
  <p>Note the method at the bottom. I was expecting this method to get me all the rows in the "Trackables" table with a "productID" column with the value of the productID variable. Instead, it seems to be returning a query which is malformed. </p>
  
  <p>The query it returns is below:</p>
  
  <pre><code>SELECT "Trackables"."trackableId" AS "Trackables_trackableId", "Trackables"."productID" AS "Trackables_productID", "Trackables"."createdOn" AS "Trackables_createdOn", "Trackables"."urlTitle" AS "Trackables_urlTitle", "Trackables"."humanTitle" AS "Trackables_humanTitle", "Trackables"."userId" AS "Trackables_userId" 
  FROM "Trackables" 
  WHERE "Trackables"."productID" = :productID_1
  </code></pre>
  
  <p>MySQL workbench is telling me the query is malformed. Further, the value in the query of productID (":productID_1") is not the actual value of the variable referenced in the code.</p>