Welcome to the Treehouse Community

The Treehouse Community is a meeting place for developers, designers, and programmers of all backgrounds and skill levels to get support. Collaborate here on code errors or bugs that you need feedback on, or asking for an extra set of eyes on your latest project. Join thousands of Treehouse students and alumni in the community today. (Note: Only Treehouse students can comment or ask questions, but non-students are welcome to browse our conversations.)

Looking to learn something new?

Treehouse offers a seven day free trial for new students. Get access to thousands of hours of content and a supportive community. Start your free trial today.

Python SQLAlchemy Basics Introduction to SQLAlchemy Querying the Movie Database

Kristen Bouzaid
seal-mask
.a{fill-rule:evenodd;}techdegree
Kristen Bouzaid
Data Analysis Techdegree Student 7,533 Points

SQLAlchemy Query to return a filtered list.."AssertionError: Regex didn't match"

OK. I'm stuck on this code challenge. The assignment is to return a list in the variable romance_movies that includes all movies in the db with the genre 'Romance'. I'm getting an "Assertion Error: Regex didn't match" on this code. The code from Line 17 and earlier was fine through the last code challenge. My only addition here is Line 20. I've tried including romance_movies = [] before Line 20. I've also tried using models.Movie rather than just Movie and using == instead of just =...not sure where to go from here so any help would be much appreciated! Thank you!

models.py
from sqlalchemy import create_engine, Column, Integer, String
from sqlalchemy.ext.declarative import declarative_base
from sqlalchemy.orm import sessionmaker


engine = create_engine(sqlite:///movies.db, echo=False)
Session = sessionmaker(bind=engine)
session = Session()
Base = declarative_base()


class Movie(Base):
    __tablename__ = movies

    id = Column(Integer, primary_key=True)
    movie_title = Column(String)
    genre = Column(String)

# Write your code below
romance_movies=session.query(Movie).filter_by(Movie.genre='Romance').all()

2 Answers

Asher Orr
seal-mask
.a{fill-rule:evenodd;}techdegree seal-36
Asher Orr
Python Development Techdegree Graduate 9,086 Points

Hi Kristen! This is the problem:

filter_by(Movie.genre='Romance').all()

Try removing the Movie. in front of genre. Like this:

romance_movies = session.query(Movie).filter_by(genre='Romance').all()

I believe Python already knows you're querying the model Class "Movie." You shouldn't have to specify it again in front of the column you're filtering by.

I hope this helps!