kopia lustrzana https://github.com/snarfed/bridgy-fed
Protocol.load bug fix, leave new/changed None if we don't know for sure
eg if local is Falsepull/568/head
rodzic
a5466e34ca
commit
342f67dfa2
|
@ -374,6 +374,8 @@ class Object(StringIdModel):
|
||||||
|
|
||||||
# Protocol and subclasses set these in fetch if this Object is new or if its
|
# Protocol and subclasses set these in fetch if this Object is new or if its
|
||||||
# contents have changed from what was originally loaded from the datastore.
|
# contents have changed from what was originally loaded from the datastore.
|
||||||
|
# If either one is None, that means we don't know whether this Object is
|
||||||
|
# new/changed.
|
||||||
new = None
|
new = None
|
||||||
changed = None
|
changed = None
|
||||||
|
|
||||||
|
|
|
@ -634,6 +634,9 @@ class Protocol:
|
||||||
def load(cls, id, remote=None, local=True, **kwargs):
|
def load(cls, id, remote=None, local=True, **kwargs):
|
||||||
"""Loads and returns an Object from memory cache, datastore, or HTTP fetch.
|
"""Loads and returns an Object from memory cache, datastore, or HTTP fetch.
|
||||||
|
|
||||||
|
Sets the :attr:`new` and :attr:`changed` attributes if we know either
|
||||||
|
one for the loaded object, ie local is True and remote is True or None.
|
||||||
|
|
||||||
Note that :meth:`Object._post_put_hook` updates the cache.
|
Note that :meth:`Object._post_put_hook` updates the cache.
|
||||||
|
|
||||||
Args:
|
Args:
|
||||||
|
@ -693,14 +696,14 @@ class Protocol:
|
||||||
obj.clear()
|
obj.clear()
|
||||||
obj.new = False
|
obj.new = False
|
||||||
else:
|
else:
|
||||||
|
obj = Object(id=id)
|
||||||
if local:
|
if local:
|
||||||
logger.info(' not in datastore')
|
logger.info(' not in datastore')
|
||||||
obj = Object(id=id)
|
|
||||||
obj.new = True
|
obj.new = True
|
||||||
obj.changed = False
|
obj.changed = False
|
||||||
|
|
||||||
cls.fetch(obj, **kwargs)
|
cls.fetch(obj, **kwargs)
|
||||||
if not obj.new:
|
if obj.new is False:
|
||||||
if orig_as1 and obj.as1:
|
if orig_as1 and obj.as1:
|
||||||
obj.changed = as1.activity_changed(orig_as1, obj.as1)
|
obj.changed = as1.activity_changed(orig_as1, obj.as1)
|
||||||
else:
|
else:
|
||||||
|
|
|
@ -250,6 +250,15 @@ class ProtocolTest(TestCase):
|
||||||
self.assertFalse(loaded.new)
|
self.assertFalse(loaded.new)
|
||||||
self.assertEqual(['foo'], Fake.fetched)
|
self.assertEqual(['foo'], Fake.fetched)
|
||||||
|
|
||||||
|
def test_load_remote_true_local_false(self):
|
||||||
|
Fake.fetchable['foo'] = our_as1={'x': 'y'}
|
||||||
|
|
||||||
|
loaded = Fake.load('foo', local=False, remote=True)
|
||||||
|
self.assertEqual({'x': 'y'}, loaded.as1)
|
||||||
|
self.assertIsNone(loaded.changed)
|
||||||
|
self.assertIsNone(loaded.new)
|
||||||
|
self.assertEqual(['foo'], Fake.fetched)
|
||||||
|
|
||||||
def test_load_remote_true_changed(self):
|
def test_load_remote_true_changed(self):
|
||||||
self.store_object(id='foo', our_as1={'content': 'stored'})
|
self.store_object(id='foo', our_as1={'content': 'stored'})
|
||||||
Fake.fetchable['foo'] = {'content': 'new'}
|
Fake.fetchable['foo'] = {'content': 'new'}
|
||||||
|
|
Ładowanie…
Reference in New Issue