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 Using Databases in Python Gettin' CRUD-y With It CRUD: Create Function

Nadine Abella
Nadine Abella
1,032 Points

maximum recursion depth exceeded

why do I get an a maximum recursion error when nothing in my scripts is even recursive?

crud.py
from models import Challenge

def create_challenge(names,languages,step= 1):
  Challenge.create(name = names,
                   language = languages)


  create_challenge("ruby","python")

3 Answers

Okay, so what he meant was that when a user calls your create_challenge function, they should not have to specify a steps argument and, if they don't, it will default to 1. Which is what you did. However, steps still needs to be passed in to create the entry. It will only default to one unless the user specifies otherwise. Here's how I solved it:

def create_challenge(new_name,new_language,new_steps=1):
  Challenge.create(name = new_name, language = new_language, steps=new_steps)
Nadine Abella
Nadine Abella
1,032 Points

thank you very much. I don't know sometimes to me the instructions are kinda vague? maybe that's just me. or maybe the variable names are clashing with something. anyway thank you

No prob :) I'm running into some of that vagueness in Java. On the plus side, I'm getting a pretty freakin' good brain workout.

It looks like your function call at the end of the code block is indented, making the function infinitely recursive.

def create_challenge(names,languages,step= 1):
  Challenge.create(name = names,
                   language = languages)


  create_challenge("ruby","python") # de-indent this line
Nadine Abella
Nadine Abella
1,032 Points

right right. like seriously I thought that was already de-dented. anyway thank you!

no prob! :)

Nadine Abella
Nadine Abella
1,032 Points
from models import Challenge

def create_challenge(names,languages,step=1):
  Challenge.create(name = names, language = languages)


create_challenge("ruby","python")

karis hutcheson it still gives me an error

Didn't find the challenge I asked you to create.

whats wrong?

Do you need to pass in the steps argument to the Challenge.create() function? I.E.

Challenge.create(name = names, language = languages, steps = step)
Nadine Abella
Nadine Abella
1,032 Points

steps is optional. I don't know what's wrong shouldn't it be right? and the only time i remember steps is when it was used by to sort the the data from the database not when it will be created so it's very confusing

I'm going to go back and do this exercise again. I'll get back to you in a minute...

Nadine Abella
Nadine Abella
1,032 Points

ok thank you. I'm been stuck on this for quite a while now