0

I'm using Django that iterate through items to see if they exists using get_or_create. Right now I'm having this problem

def insert_titles(self):
    game = None
    title = None
    for k,v in self.data.items():


        game_exists = Game.objects.all().get_or_create(game_name=v['title']) #will get RuntimeError: maximum recursion depth exceeded in cmp
        print game_exists

Basically, this is an script that will run as a cron job, so I kind of have to iterate through a bunch of items to get to the point I want

            while True:
            try:

                data = strategy.process()
                filter = FilterGames(data, link) 

Filter Games code:

def __init__(self, data):
    self.data = data
    self.insert_titles()
    print "init"

I've done this in the past with Play Framework, maybe since I'm still inexperienced in Python I'm looking at it the wrong way, not sure how to proceed when it gives me this type of error. I have tried change the structure a bit to no avail. Weird thing is that if I use a string in game_name it will work as expected, but if I use data gathered from a loop, it starts throwing that error.

Finally, I want to know how to correct this type of error, and hopefully understand a bit more of why it does that.

4

1 回答 1

1

Okay, so after poking and investigating why it did that. I noticed that the type of the object wasn't a true string type, or in this case str. I use BeautifulSoup to get data from some XML files and when I used bs4.find().string it gave me a NavigableString instead of a normal string.

So for future reference, be sure that the type is the right one. Feeding a NavigableString to Django filter gave me this unexpected error

于 2013-01-22T16:13:42.783 回答