1

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?

1 Answer 1

3

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?

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.