edgeflip / faraday

Pythonic modeling framework for DynamoDB
Other
0 stars 0 forks source link

get-or-create #18

Open jesteria opened 10 years ago

jesteria commented 10 years ago

The item manager should provide a method encapsulating the non-trivial logic of get-or-create, a la:

try:
    return get(…)
except DoesNotExist:
    item = Item(…)
    try:
        item.save()
    except ConditionalCheckFailedException:
        exc_info = sys.exc_info()
        try:
            return get()
        except DoesNotExist:
            six.reraise(*exc_info)
    else:
        return item