Protocol.load bug fix, leave new/changed None if we don't know for sure

eg if local is False
pull/568/head
Ryan Barrett 2023-06-28 15:27:11 -07:00
rodzic a5466e34ca
commit 342f67dfa2
Nie znaleziono w bazie danych klucza dla tego podpisu
ID klucza GPG: 6BE31FDF4776E9D4
3 zmienionych plików z 18 dodań i 4 usunięć

Wyświetl plik

@ -374,6 +374,8 @@ class Object(StringIdModel):
# 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.
# If either one is None, that means we don't know whether this Object is
# new/changed.
new = None
changed = None

Wyświetl plik

@ -634,6 +634,9 @@ class Protocol:
def load(cls, id, remote=None, local=True, **kwargs):
"""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.
Args:
@ -693,14 +696,14 @@ class Protocol:
obj.clear()
obj.new = False
else:
obj = Object(id=id)
if local:
logger.info(' not in datastore')
obj = Object(id=id)
obj.new = True
obj.changed = False
obj.new = True
obj.changed = False
cls.fetch(obj, **kwargs)
if not obj.new:
if obj.new is False:
if orig_as1 and obj.as1:
obj.changed = as1.activity_changed(orig_as1, obj.as1)
else:

Wyświetl plik

@ -250,6 +250,15 @@ class ProtocolTest(TestCase):
self.assertFalse(loaded.new)
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):
self.store_object(id='foo', our_as1={'content': 'stored'})
Fake.fetchable['foo'] = {'content': 'new'}