Repository navigation
Description
What's needed?
SourceProperties is a mutable dataclass (code), and the resampler gives its own instance of each source to users: Resampler.get_source_properties() returns it (code), and resampling functions receive it at every call (code).
The resampler also uses these fields as its own state. It estimates the input period from sampling_start and received_samples, only while sampling_period is None (code), and it finds new dropped samples by comparing with dropped_samples (code). #1501 adds current_windows_without_samples, which also decides when the missing samples are logged.
So writing to any of these fields, even by mistake, changes how the resampler works, and nothing prevents it.
Proposed solution
Keep the mutable object private to the resampler, and give users a read-only view of it, or a copy. A copy is simpler, but resampling functions would need a new one for every window of every source, so a read-only view is probably better there.
Changing what users get could break code that writes to it, so it might need a deprecation period. If only mutability of fields is changed, then it can ship as a bug fix, as changing the source properties was never intended to work.
Use cases
Applications read the source properties to check how healthy a timeseries is, through Resampler.get_source_properties() or in a custom resampling function. They should be able to do that without any risk of breaking the resampler.
Alternatives and workarounds
Documenting that the fields must not be modified is the cheapest option, but nothing enforces it.
Making SourceProperties frozen, and replacing it with a new instance on every update, would need a new object for every sample received, as received_samples changes with each one. Adding samples must be as fast as possible, so that's probably too slow.
Additional context
Found during the review of #1501: #1501 (comment)
Metadata
Metadata
Assignees
Labels
Type
Fields
Priority
Projects
- StatusShow more project fieldsTo do
Activity