MrCooL
MrCooL

Reputation: 926

Many to Many Relationship + Google Datastore + Python

Given the log of following:

Restaurant = <persistence.model.Restaurant object at 0x3913c01e89e78a20>
Review Content = This is my first comment...
User[0] = <persistence.model.User object at 0x3913c01e89e780a0>

and following codes:

class RestaurantReview(db.Model):
    owned_by = db.ReferenceProperty(Restaurant, required=True, collection_name='restaurant')
    written_by = db.ReferenceProperty(User, required=True, collection_name='user')
    content = db.StringProperty(required=True)
    date = db.DateTimeProperty(auto_now_add=True)

When I was trying to create the instance of RestaurantReview, it just never work:

RestaurantReview(owned_by=restaurant, written_by=user[0], content=restaurant_review_content.__str__()).put()    

EDIT Any idea what's happening? It keeps throwing the custom error that I set.

try:

        RestaurantReview(owned_by=restaurant, written_by=user[0], content=restaurant_review_content.__str__()).put()
    except:
        logging.error('CUSTOM ERROR: Review for restaurant has not been added')

Upvotes: 0

Views: 163

Answers (1)

bpgergo
bpgergo

Reputation: 16037

I suggest to rethrow the error by calling raise

try:
    RestaurantReview(owned_by=restaurant, written_by=user[0], content=restaurant_review_content.__str__()).put()
except:
    logging.error('CUSTOM ERROR: Review for restaurant has not been added')
    raise

Upvotes: 1

Related Questions