app-engine-ndb

How to Clear/Invalidate NDB Cache in Tests

*爱你&永不变心* 提交于 2019-12-14 02:33:45
问题 I have a simple NDB Model with an instance attribute, which is not an NDB property. I want to test that the property value gets lost when the entity is saved and retrieved from the datastore. Now when the entity is retrieved it is the same instance as the one that has been put to the datastore. Is there a way to programatically clear/invalidate the memcache and the NDB in-memory cache ? The example is a pytest test, sorry for that. from google.appengine.ext import testbed, ndb class User(ndb

How do I refresh an NDB entity from the datastore?

微笑、不失礼 提交于 2019-12-13 18:37:25
问题 I'd like to be able to assert in tests that my code called Model.put() for the entities that were modified. Unfortunately, there seems to be some caching going on, such that this code: from google.appengine.ext import ndb class MyModel(ndb.Model): name = StringProperty(indexed=True) text = StringProperty() def update_entity(id, text): entity = MyModel.get_by_id(id) entity.text = text # This is where entity.put() should happen but doesn't Passes this test: def test_updates_entity_in_datastore

Is it possible to set two fields as indexes on an entity in ndb?

旧时模样 提交于 2019-12-13 16:14:44
问题 I am new to ndb and gae and have a problem coming up with a good solution setting indexes. Let say we have a user model like this: class User(ndb.Model): name = ndb.StringProperty() email = ndb.StringProperty(required = True) fb_id = ndb.StringProperty() Upon login if I was going to check against the email address with a query, I believe this would be quite slow and inefficient. Possibly it has to do a full table scan. q = User.query(User.email == EMAIL) user = q.fetch(1) I believe it would

Can ndb.KeyProperty reference a base model class when using model inheritance?

蹲街弑〆低调 提交于 2019-12-13 13:14:50
问题 I have some models that share a common set of properties, which I have defined in a base model class from which other models inherit: class BaseUser(ndb.Model): name = ndb.StringProperty() class DerivedUserA(BaseUser): # some additional properties... class DerivedUserB(BaseUser): # some additional properties... In some other model, I need a reference to any BaseUser -derived model: class MainModel(ndb.Model): user = ndb.KeyProperty(kind = BaseUser) However, When I try to set a DerivedUserA

Google App Engine: Modifying 1000 entities

岁酱吖の 提交于 2019-12-13 07:46:32
问题 I have about 1000 user account entities like this: class UserAccount(ndb.Model): email = ndb.StringProperty() Some of these email values contain uppercase letters like JohnathanDough@email.com . I want to select all the email values from all UserAccount entities and apply python's email.lower() . How can I do this efficiently, and most importantly, without errors? Note: The email values are important for login, so I cannot afford to mess this up. Is there a way to backup this data in case of

Google App Engine Datastore entities. Efficiency and structure

走远了吗. 提交于 2019-12-13 07:13:31
问题 I am interested in knowing the best structure, for speed and cost efficiency, of Google App Engine Datastore entities. As an example, an app about Clubs. Structure A: A single ndb.Model entity per club with: Name, ID, Address, Contacts, Tags, Reviews, Images etc Structure B: Multiple Entities per club with a KeyProperty referencing the club. ndb.Model Entity A. Name and ID ndb.Model Entity B. Address ndb.Model Entity C. Contacts etc Considering that users might only want to look up addresses

How to ensure that my entity will never be an orphan?

一曲冷凌霜 提交于 2019-12-13 05:51:38
问题 Sometimes, you make an entity kind that is supposed to exist in another entity. However, if it turns into an orphan, it will have no reason to exist in the datastore anymore. What happens to child datastore objects after deleting the ancestor? According to the link above, "Child entities do not get deleted when the ancestor is deleted" "child_entity.key.parent().get() will return None." If I delete the ancestor, the child will have no parent, making it an orphan. This is a problem, as there

AppEngine NDB property validations

本小妞迷上赌 提交于 2019-12-13 03:07:19
问题 I wonder what the best approach is for validating NDB entity properties likes: a date must be in the future a grade (integer property) must be between 1 and 10 a reference to another entity must have certain property values (e.g. book.category.active must be True) I'm also using WTForms to validate submitted requests, but I want to enforce validations also on a lower level like the datastore entities itself. So basically what I'm looking for is to call a validate on a datastore entity to see

Ndb strong consistency and frequent writes

放肆的年华 提交于 2019-12-13 02:56:02
问题 I'm trying to achieve strong consistency with ndb using python. And looks like I'm missing something as my reads behave like they're not strongly consistent. The query is: links = Link.query(ancestor=lead_key).filter(Link.last_status == None).fetch(keys_only=True) if links: do_action() The key structure is: Lead root (generic key) -> Lead -> Website (one per lead) -> Link I have many tasks that are executed concurrently using TaskQueue and this query is performed at the end of every task.

AppEngine MapReduce NDB, DeadlineExceededError

守給你的承諾、 提交于 2019-12-13 02:44:06
问题 we're trying to heavily use MapReduce in our project. Now we have this problem, there is a lots of ' DeadlineExceededError ' errors in the log... One example of it ( traceback differs each time a bit ) : Traceback (most recent call last): File "/base/python27_runtime/python27_lib/versions/1/google/appengine/runtime/wsgi.py", line 207, in Handle result = handler(dict(self._environ), self._StartResponse) File "/base/python27_runtime/python27_lib/versions/third_party/webapp2-2.3/webapp2.py",