disable ndb in-memory cache

it has a bug/weird behavior that we want to avoid, at least for now.

https://github.com/googleapis/python-ndb/issues/888
https://github.com/snarfed/bridgy-fed/issues/558
pull/561/head
Ryan Barrett 2023-06-22 14:27:02 -07:00
rodzic c97ee862a5
commit cba4845394
Nie znaleziono w bazie danych klucza dla tego podpisu
ID klucza GPG: 6BE31FDF4776E9D4
7 zmienionych plików z 39 dodań i 7 usunięć

Wyświetl plik

@ -47,7 +47,12 @@ app.url_map.merge_slashes = False
app.url_map.redirect_defaults = False
app.wsgi_app = flask_util.ndb_context_middleware(
app.wsgi_app, client=appengine_config.ndb_client)
app.wsgi_app, client=appengine_config.ndb_client,
# disable in-memory cache
# (also in tests/testutil.py)
# https://github.com/googleapis/python-ndb/issues/888
cache_policy=lambda key: False,
)
cache = Cache(app)

Wyświetl plik

@ -1124,7 +1124,8 @@ class ActivityPubTest(TestCase):
labels=['activity'])
obj.deleted = True
self.assert_entities_equal(obj, protocol.objects_cache['http://an/obj'])
self.assert_entities_equal(obj, protocol.objects_cache['http://an/obj'],
ignore=['expire', 'created', 'updated'])
def test_update_note(self, *mocks):
Object(id='https://a/note', as2={}).put()

Wyświetl plik

@ -116,6 +116,26 @@ class ObjectTest(TestCase):
super().setUp()
g.user = None
def test_ndb_in_memory_cache_off(self):
"""It has a weird bug that we want to avoid.
https://github.com/googleapis/python-ndb/issues/888
"""
from google.cloud.ndb import Model, StringProperty
class Foo(Model):
a = StringProperty()
f = Foo(id='x', a='asdf')
f.put()
# print(id(f))
f.a = 'qwert'
got = Foo.get_by_id('x')
# print(got)
# print(id(got))
self.assertEqual('asdf', got.a)
def test_proxy_url(self):
obj = Object(id='abc', source_protocol='bluesky')
self.assertEqual('http://localhost/convert/bluesky/web/abc',

Wyświetl plik

@ -55,10 +55,10 @@ class PagesTest(TestCase):
def test_user_web_custom_username_doesnt_redirect(self):
"""https://github.com/snarfed/bridgy-fed/issues/534"""
self.user.obj = Object(id='a', as2={
self.user.obj_key = Object(id='a', as2={
**ACTOR_AS2,
'url': 'acct:baz@user.com',
})
}).put()
self.user.put()
self.assertEqual('baz', self.user.username())

Wyświetl plik

@ -227,11 +227,13 @@ class ProtocolTest(TestCase):
self.assertEqual(['foo'], Fake.fetched)
def test_load_remote_true_unchanged(self):
obj = self.store_object(id='foo', our_as1={'x': 'stored'})
obj = self.store_object(id='foo', our_as1={'x': 'stored'},
source_protocol='fake')
Fake.objects['foo'] = {'x': 'stored'}
loaded = Fake.load('foo', remote=True)
self.assert_entities_equal(obj, loaded)
self.assert_entities_equal(obj, loaded,
ignore=['expire', 'created', 'updated'])
self.assertFalse(loaded.changed)
self.assertFalse(loaded.new)
self.assertEqual(['foo'], Fake.fetched)

Wyświetl plik

@ -199,6 +199,7 @@ class WebfingerTest(TestCase):
'acct:notthisuser@boop.org',
'acct:customuser@user.com',
]
self.user.obj.put()
self.user.put()
for resource in (

Wyświetl plik

@ -139,7 +139,10 @@ class TestCase(unittest.TestCase, testutil.Asserts):
# clear datastore
requests.post(f'http://{ndb_client.host}/reset')
self.ndb_context = ndb_client.context()
# disable in-memory cache
# (also in flask_app.py)
# https://github.com/googleapis/python-ndb/issues/888
self.ndb_context = ndb_client.context(cache_policy=lambda key: False)
self.ndb_context.__enter__()
util.now = lambda **kwargs: testutil.NOW