Skip to content

python(fix): support nested calculated channel references#580

Merged
wei-qlu merged 8 commits into
mainfrom
python/nested-calculated-channels
May 22, 2026
Merged

python(fix): support nested calculated channel references#580
wei-qlu merged 8 commits into
mainfrom
python/nested-calculated-channels

Conversation

@wei-qlu
Copy link
Copy Markdown
Contributor

@wei-qlu wei-qlu commented May 20, 2026

Summary

  • Surfaces a calculated_channel: CalculatedChannel | str field on ChannelReference and routes it into the proto's calculated_channel_version_id oneof when serializing calculated channels (create + update), rules (create + update), and exports. A CalculatedChannel input is normalized to its version_id via a validator; a string is interpreted as a version_id directly.
  • Skips the name-based channel lookup in resolve_calculated_channels when a version reference is already provided, so nested references don't get treated as native channel lookups and fail.
  • Updates Rule._from_proto and ChannelReference._from_proto to read the version ID back off the proto oneof on the response path.

Use case:

cc = client.calculated_channels.find(name="TEST_CC")

# Reference the latest version (cc IS the latest)
ChannelReference(channel_reference="$1", calculated_channel=cc)

# Pin to a specific version_id (e.g., copied from the UI)
ChannelReference(channel_reference="$1", calculated_channel="8feb6ccd-...")

Validation

  • Unit tests covering:
    • ChannelReference validation and proto round-tripping (oneof read + write), including object input, string input, and rejection cases
    • Calculated channel serialization on both Create and Update paths
    • Rules serialization helper in both directions, plus Rule._from_proto round trip
    • resolve_calculated_channels skipping the name lookup when a version reference is provided
  • Manually created and updated a nested CC using the new calculated_channel field on ChannelReference and confirmed there were no missing dependents.
  • Manually created a rule whose expression references a CC by version_id and confirmed it evaluated correctly.

@github-actions
Copy link
Copy Markdown
Contributor

github-actions Bot commented May 20, 2026

Python docs preview: https://sift-stack.github.io/sift/python/pr-580/

Deployed from fd38af5. The link may take up to a minute to become live as GitHub Pages propagates.

@wei-qlu wei-qlu marked this pull request as ready for review May 20, 2026 22:50
Comment thread python/lib/sift_client/sift_types/channel.py Outdated
@wei-qlu wei-qlu requested a review from alexluck-sift May 21, 2026 22:38
Comment thread python/lib/sift_client/_internal/low_level_wrappers/rules.py Outdated
Comment thread python/lib/sift_client/sift_types/channel.py Outdated
@wei-qlu wei-qlu requested a review from alexluck-sift May 22, 2026 00:03
@wei-qlu wei-qlu merged commit e73894a into main May 22, 2026
22 checks passed
@wei-qlu wei-qlu deleted the python/nested-calculated-channels branch May 22, 2026 00:10
@wei-qlu wei-qlu changed the title python(feat): support nested calculated channel references python(fix): support nested calculated channel references May 22, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants