Why do I get RecursionError only for 1 case using the same variable when inserting an item in dynamoDB

I am seeing a really strange behaviour in python 3, and boto3 when inserting an item to dynamoDB.

# Assume that set_original() returns a dictionary
original = set_original()

# copy is an EXACT copy of original, but hardcoded.
copy = {..hardcoded "original" dictionary..}

I can confirm that both dictionaries are the same, as the following returns True:

if copy == original:
    return True

Right now this is failing with an enormous RecursionError: maximum recursion depth exceeded while calling a Python object

table.put_item(Item=original)

But this works just fine and successfully inserts the data in dynamodb:

table.put_item(Item=copy)

What can possibly be happening? I checked and type(), and dir() return the same for both, they are basically copies of each other, but only one fails to insert, while the other one doesn't.

Upvotes: 0

Views: 978

Answers (1)

Although I don't know the exact reason on why this is happening, I solved as follows: set_original() was creating a dict in which one of the variables was not a str, but rather a beautiful soup string: <class 'bs4.element.NavigableString'> This is okay for python, but it's not okay for dynamoDB. Solution was basically to convert all these NavigableString to str type.

Upvotes: 1

Related Questions