Reputation: 13
I'm working on a database-centric project with a fellow programmer. We have the following code for retrieving information from our database:
# create connection to database
engine = create_engine(URL(**DATABASE))
Session = sessionmaker(bind=engine)
session = Session()
# construct query
query = session.query(MediaText.line_number, MediaText.start_time_stamp, MediaText.end_time_stamp).\
filter(MediaText.oclc_id == oclcId)
# get info about first line to snapshot
line_to_snapshot = query.fetchone()
When I try to run the code, I get the following error:
AttributeError: 'Query' object has no attribute 'fetchone'
What's confusing is that my partner can run the code just fine. We're both running Python 3.4 and have version 1.0.9 of the SQLAlchemy library on our systems. Does anyone know what could be going wrong here?
Upvotes: 1
Views: 6754
Reputation: 715
From SQLALchemy's Query API and from what I know (Python 2.7 and sqlalchemy 1.0.4) fetchone
is not part of the Query
API, although one
is.
How about changing it to:
line_to_snapshot = query.one()
and see if it works?
Upvotes: 3