def update_record( db: PartitionedDatabase, record_id: RecordId, body: JsonDict ) -> JsonDict: x_bf_trace_id = AuditLogger.trace_id_header() record = db.get_record(record_id, embed_linked=False, fill_missing=True) if record is None: raise NotFound(f"Could not get record {record_id}") model = db.get_model_of_record(record) if model is None: raise NotFound(f"Cound not find model for record {record_id}") properties = db.get_properties(model) updated_record = db.update_record(record_id, body["values"]) # Emit "UpdateRecord" event: PennsieveJobsClient.get().send_changelog_event( organization_id=db.organization_id, dataset_id=db.dataset_id, user_id=db.user_id, event=UpdateRecord( id=record.id, name=record.name, model_id=model.id, properties=UpdateRecord.compute_diff( properties, record.values, updated_record.values ), ), trace_id=TraceId(x_bf_trace_id), ) return updated_record.to_dict()
def delete_record(db: PartitionedDatabase, record_id: RecordId) -> None: x_bf_trace_id = AuditLogger.trace_id_header() model = db.get_model_of_record(record_id) if model is None: raise NotFound(f"Cound not find model for record {record_id}") properties = db.get_properties(model) deleted = db.delete_record(record_id, properties) # Emit "DeleteRecord" event: PennsieveJobsClient.get().send_changelog_event( organization_id=db.organization_id, dataset_id=db.dataset_id, user_id=db.user_id, event=DeleteRecord(id=deleted.id, name=deleted.name, model_id=model.id), trace_id=TraceId(x_bf_trace_id), ) return None