google-cloud-datastore

Cloud Datastore: ways to avoid race conditions

六月ゝ 毕业季﹏ 提交于 2019-12-02 09:56:47
I have lots of views manipulating entities of same kind: def view1(request, key): user = ndb.Key(urlsafe=key).get() user.x = 1 user.put() ... def view2(request, key): user = ndb.Key(urlsafe=key).get() user.y = 2 user.put() ... Obviously, this is error-prone due to possible race conditions (last wins): view1 reads whole user entity data (x=None, y=None) view2 reads whole user entity data (x=None, y=None) view1 user.x = 1 (x=1, y=None) view2 user.y = 2 (x=None, y=2) view1 user.put() (x=1, y=None) view2 user.put() (x=None, y=2) What are best ways to fix this and what behaviour is considered most

Checking uniqueness contraint during form validation in App Engine

ε祈祈猫儿з 提交于 2019-12-02 09:46:18
I am using Flask and WTforms in App Engine, trying to implement uniqueness contraint on one of the field. The question is big, please be patient and I have been stuck here from many hours, need some help from you people. Started learning App Engine, Flask and WTForms a month ago. Thanks in advance. Application has model 'Team' as shown below: class Team(db.Model): name = db.StringProperty(required=True) -- some other fields here -- Requirement: Name of the team has to be unique. I have followed the links http://www.codigomanso.com/en/2010/09/solved-anadir-claves-unicas-en-google-app-engine-en

How to check duplicate data in my datastore and display the error?

筅森魡賤 提交于 2019-12-02 09:41:32
Am working on GAE,GAE datastore and python. This is my dbmodel.py, class Customer(db.Model): name = db.StringProperty(required=True) phone = db.PhoneNumberProperty(required=True) email = db.EmailProperty(required=True) this is my main.py, class AddCustomerHandler(BaseHandler): def get(self): template = jinja_environment.get_template('template/addcustomer.html') self.response.out.write(template.render(template_values)) def post(self): input_fullname=self.request.get('fullname') input_phone=self.request.get('phone') input_email=self.request.get('email') newcustomer=Customer(name=input_fullname

Efficient way to store relation values in NDB

折月煮酒 提交于 2019-12-02 09:33:13
I've this data model (I made it, so if there's a better way to do it, please let me know). Baically I've Club that can have many Courses . now I want to know all the members and instructors of a Club. members and instructors are stored in the Course model, and Club has a reference to them. See the code.. class Course(ndb.Model): ... instructor_keys = ndb.KeyProperty(kind="User", repeated=True) member_keys = ndb.KeyProperty(kind="User", repeated=True) @property def instructors(self): return ndb.get_multi(self.instructor_keys) @property def members(self): return filter(lambda x: x.is_active, ndb

google datastore token not authorized?

て烟熏妆下的殇ゞ 提交于 2019-12-02 09:29:36
jwt1=`echo -n '{"alg":"RS256","typ":"JWT"}' | openssl base64 -e` jwt2=`echo -n '{\ "iss":"...@developer.gserviceaccount.com",\ "scope":"https://www.googleapis.com/auth/userinfo.email https://www.googleapis.com/auth/datastore",\ "aud":"https://accounts.google.com/o/oauth2/token",\ "exp":'$(($(date +%s)+3600))',\ "iat":'$(date +%s)'}' | openssl base64 -e` jwt3=`echo -n "$jwt1.$jwt2" | tr -d '\n' | tr -d '=' | tr '/+' '_-'` jwt4=`echo -n "$jwt3" | openssl sha -sha256 -sign google.p12 | openssl base64 -e` jwt5=`echo -n "$jwt4" | tr -d '\n' | tr -d '=' | tr '/+' '_-'` curl -H "Content-type:

jQuery Autocomplete with Remote JSON Source + Google App Engine + Python

冷暖自知 提交于 2019-12-02 08:49:37
So let's say I have a webapp which just lets users save their hobbies. So I have Kind like this: class Hobby(ndb.Model): hobby_name = ndb.StringProperty() Users just create Hobby entities using this form: <form action="/new-hobby" method="post"> <input type="text" name="hobby_name" id="new-hobby" /> <input type="submit" value="Save New Hobby" /> </form> Then this form is handled by this: # Handles /new-hobby class NewHobby(webapp2.RequestHandler): def post(self): hobby_name = self.request.get('hobby_name') if hobby_name: h = Hobby(hobby_name = hobby) h.put() app = webapp2.WSGIApplication([ ('

In Google DataStore GQL, how can I group the WHERE terms?

情到浓时终转凉″ 提交于 2019-12-02 08:38:36
I need to group terms in the WHERE clause. For example, WHERE (param1='foo1' OR param1='foo2') AND (param2='bar1' OR param2='bar2') But it's giving me a syntax error saying that the parentheses are "unexpected". The actual error is: GQL query error: Encountered "(" at line 1, column 29. Was expecting one of: "false", "null", "true", <INTEGER>, <DOUBLE>, <SINGLE_QUOTE_STRING>, <DOUBLE_QUOTE_STRING>, <UNQUOTED_NAME>, <QUOTED_NAME>, <NAME_BINDING_SITE>, <POSITION_BINDING_SITE> So, is there any way for me to run that query? I believe the problem you're facing comes from the OR operator - GQL doesn

How to create API methods in Google App Engine that have several decedents/ancestors

白昼怎懂夜的黑 提交于 2019-12-02 08:32:03
问题 I am having trouble understanding how to structure an ancestor tree with several decedents. Suppose I have a model like this (every Entity has a Long id ): User -Post -Comment Where the Comment is the grandchild of the User . What is really annoying is to insert a Comment I need to generate the Key of the Post . And to generate the Key of the Post I also need to know the ID of the User : Key<Post> postKey = Key.create(Key.create(User.class, userId), Post.class, postId); This is a problem for

Deleted Datastore entries reappear

夙愿已清 提交于 2019-12-02 08:14:06
I'd like to re-open Deleted Datastore entries reappear as a registered user. Can the old question be deleted? I'll try to be more specific this time. I'm experiencing the following problem: Initially I put N entities of the same kind into the Datastore like that: datastore_entity = MyModel(model_property=property_value) datastore_entity.put() Afterwards I delete them. I have used the Datastore Admin interface as well as a self-defined handler for the mapreduce library in order to do so. The deleted entities do not appear neither in the Datastore viewer nor in the Datastore Admin view. When I

Error every time I run datastore.runQuery: one of fields Query.query and Query.gql_query must be set

天涯浪子 提交于 2019-12-02 07:56:30
I'm trying to run a simple query against my Google Cloud datastore using google-api-nodejs-client. I want to query for all entities matching a given kind. When I run this query using the "Try it now" tool it works fine: Request POST https://www.googleapis.com/datastore/v1beta2/datasets/healthier-staging/runQuery?key={YOUR_API_KEY} { "query": { "kinds": [ { "name": "Subscriber" } ] } } Response 200 OK { "batch": { "entityResultType": "FULL", "entityResults": [ { "entity": { "key": { "partitionId": { "datasetId": "s~healthier-staging" }, "path": [ { "kind": "Subscriber", "name": "+1215XXXXXXX" }