diff --git a/swh/storage/in_memory.py b/swh/storage/in_memory.py --- a/swh/storage/in_memory.py +++ b/swh/storage/in_memory.py @@ -1049,6 +1049,8 @@ assert 'id' not in origin origin_id = self._origin_id(origin) if origin_id is None: + if self.journal_writer: + self.journal_writer.write_addition('origin', origin) # origin ids are in the range [1, +inf[ origin_id = len(self._origins) + 1 origin['id'] = origin_id @@ -1059,9 +1061,6 @@ else: origin['id'] = origin_id - if self.journal_writer: - self.journal_writer.write_addition('origin', origin) - return origin_id def fetch_history_start(self, origin_id): @@ -1132,6 +1131,7 @@ if self.journal_writer: origin = self.origin_get([{'id': origin_id}])[0] + del origin['id'] self.journal_writer.write_addition('origin_visit', { **visit, 'origin': origin}) @@ -1161,6 +1161,7 @@ raise ValueError('Invalid origin_id or visit_id') from None if self.journal_writer: origin = self.origin_get([{'id': origin_id}])[0] + del origin['id'] self.journal_writer.write_update('origin_visit', { 'origin': origin, 'visit': visit_id, 'status': status or visit['status'], diff --git a/swh/storage/storage.py b/swh/storage/storage.py --- a/swh/storage/storage.py +++ b/swh/storage/storage.py @@ -1138,19 +1138,20 @@ if isinstance(date, str): date = dateutil.parser.parse(date) - visit = db.origin_visit_add(origin, date, cur) + visit_id = db.origin_visit_add(origin_id, date, cur) if self.journal_writer: # We can write to the journal only after inserting to the # DB, because we want the id of the visit origin = self.origin_get([{'id': origin_id}], db=db, cur=cur)[0] + del origin['id'] self.journal_writer.write_addition('origin_visit', { - 'origin': origin, 'date': date, 'visit': visit, + 'origin': origin, 'date': date, 'visit': visit_id, 'status': 'ongoing', 'metadata': None, 'snapshot': None}) return { 'origin': origin_id, - 'visit': visit, + 'visit': visit_id, } @db_transaction() @@ -1192,6 +1193,7 @@ if self.journal_writer: origin = self.origin_get( [{'id': origin_id}], db=db, cur=cur)[0] + del origin['id'] self.journal_writer.write_update('origin_visit', { **visit, **updates, 'origin': origin}) @@ -1450,12 +1452,10 @@ if origin_id: return origin_id - origin['id'] = db.origin_add(origin['type'], origin['url'], cur) - if self.journal_writer: self.journal_writer.write_addition('origin', origin) - return origin['id'] + return db.origin_add(origin['type'], origin['url'], cur) @db_transaction() def fetch_history_start(self, origin_id, db=None, cur=None): diff --git a/swh/storage/tests/test_storage.py b/swh/storage/tests/test_storage.py --- a/swh/storage/tests/test_storage.py +++ b/swh/storage/tests/test_storage.py @@ -536,6 +536,8 @@ class twice. """ + maxDiff = None + @staticmethod def normalize_entity(entity): entity = copy.deepcopy(entity) @@ -1065,6 +1067,9 @@ }])[0] self.assertEqual(actual_origin2['id'], origin2['id']) + del actual_origin['id'] + del actual_origin2['id'] + self.assertEqual(list(self.journal_writer.objects), [('origin', actual_origin), ('origin', actual_origin2)]) @@ -1202,7 +1207,6 @@ }]) expected_origin = self.origin2.copy() - expected_origin['id'] = origin_id data = { 'origin': expected_origin, 'date': self.date_visit2, @@ -1297,9 +1301,7 @@ }]) expected_origin = self.origin2.copy() - expected_origin['id'] = origin_id expected_origin2 = self.origin.copy() - expected_origin2['id'] = origin_id2 data1 = { 'origin': expected_origin, 'date': self.date_visit2, @@ -1501,7 +1503,6 @@ self.assertEqual(by_ov, self.empty_snapshot) expected_origin = self.origin.copy() - expected_origin['id'] = origin_id data1 = { 'origin': expected_origin, 'date': self.date_visit1, @@ -1539,7 +1540,6 @@ self.assertEqual(by_ov, self.empty_snapshot) expected_origin = self.origin.copy() - expected_origin['id'] = origin_id data1 = { 'origin': expected_origin, 'date': self.date_visit1, @@ -1801,7 +1801,6 @@ self.assertEqual(by_ov2, self.snapshot) expected_origin = self.origin.copy() - expected_origin['id'] = origin_id data1 = { 'origin': expected_origin, 'date': self.date_visit1, @@ -1864,7 +1863,6 @@ self.assertEqual(by_ov2, self.snapshot) expected_origin = self.origin.copy() - expected_origin['id'] = origin_id data1 = { 'origin': expected_origin, 'date': self.date_visit1,