User.get_or_create: if the id is a copy, return the original

...which will be in a different protocol! worried this will break something. hrm.
pull/968/head
Ryan Barrett 2024-04-23 17:56:59 -07:00
rodzic 0f89b0750a
commit 506de7fd1d
Nie znaleziono w bazie danych klucza dla tego podpisu
ID klucza GPG: 6BE31FDF4776E9D4
2 zmienionych plików z 7 dodań i 0 usunięć

Wyświetl plik

@ -244,6 +244,8 @@ class User(StringIdModel, metaclass=ProtocolUserMeta):
if not propagate:
return user
else:
if orig := get_original(id):
return orig
user = cls(id=id, **kwargs)
user.existing = False

Wyświetl plik

@ -138,6 +138,11 @@ class UserTest(TestCase):
self.assertEqual('y.z', got.key.id())
assert got.existing
def test_get_or_create_by_copies(self):
other = self.make_user(id='other:ab', cls=OtherFake,
copies=[Target(uri='fake:ab', protocol='fake')])
self.assert_entities_equal(other, Fake.get_or_create('fake:ab'))
def test_get_or_create_opted_out(self):
user = self.make_user('fake:user', cls=Fake,
obj_as1 = {'summary': '#nobridge'})