Welcome to the Treehouse Community

Want to collaborate on code errors? Have bugs you need feedback on? Looking for an extra set of eyes on your latest project? Get support with fellow developers, designers, and programmers of all backgrounds and skill levels here with the Treehouse Community! While you're at it, check out some resources Treehouse students have shared here.

Looking to learn something new?

Treehouse offers a seven day free trial for new students. Get access to thousands of hours of content and join thousands of Treehouse students and alumni in the community today.

Start your free trial

Python SQLAlchemy Basics Introduction to SQLAlchemy Querying the Movie Database

Kristen Bouzaid
Kristen Bouzaid
Data Analysis Techdegree Student 7,748 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!

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

2 Answers

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

Hi Kristen! This is the problem:


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!