Skip to content

Commit

Permalink
Set lineage and lineage_hash simultaneously (#861)
Browse files Browse the repository at this point in the history
* Make sure lineage of `DataKey` can not be directly changed

* Set `lineag` and `lineage_hash` simultaneously
  • Loading branch information
dachengx authored Aug 2, 2024
1 parent 63100f5 commit a58cd5d
Showing 1 changed file with 11 additions and 8 deletions.
19 changes: 11 additions & 8 deletions strax/storage/common.py
Original file line number Diff line number Diff line change
Expand Up @@ -35,10 +35,8 @@ class DataKey:

run_id: str
data_type: str
lineage: dict

# Do NOT use directly, use the lineage_hash method
_lineage_hash = ""
_lineage: dict
_lineage_hash: str

def __init__(self, run_id, data_type, lineage):
self.run_id = run_id
Expand All @@ -48,13 +46,18 @@ def __init__(self, run_id, data_type, lineage):
def __repr__(self):
return "-".join([self.run_id, self.data_type, self.lineage_hash])

@property
def lineage(self):
return self._lineage

@lineage.setter
def lineage(self, value):
self._lineage = value
self._lineage_hash = strax.deterministic_hash(value)

@property
def lineage_hash(self):
"""Deterministic hash of the lineage."""
# We cache the hash computation to benefit tight loops calling
# this property
if self._lineage_hash == "":
self._lineage_hash = strax.deterministic_hash(self.lineage)
return self._lineage_hash


Expand Down

0 comments on commit a58cd5d

Please sign in to comment.