Skip to content

Add is_open convenience to GetConfigurationActivationApiResult #26

Description

@craigmcchesney

Split out from #20, which noted this as worth pairing with the open-ended activation fix but left it out of #25 to keep that diff minimal ahead of the release.

Now that end_time is optional (#25), an activation can be open-ended — endTime genuinely absent, meaning "still in effect". Callers need to detect that shape, not just create it. The motivating case is the live bridge from #20: to close an interval you must first identify the open one.

Current state

The only way to ask "is this still open" is to reach into the protobuf directly:

still_open = not activation.HasField("endTime")

That is what doc/cookbook/machine-configuration.md currently shows. It works, but it pushes a protobuf presence check into user code for what is a first-class domain question, and it requires the caller to know that absent-vs-zero is the distinction that matters.

Suggested change

Add a convenience to GetConfigurationActivationApiResult (machine_config_client.py:477 neighborhood, alongside the existing configuration_activation property):

@property
def is_open(self) -> Optional[bool]:
    """True if the activation is open-ended (still in effect), None if there is no record."""

Returning Optional[bool] keeps it honest on the error path, where configuration_activation is already None — an is_open of False would wrongly imply a closed record exists.

Worth considering the same accessor on the query/iterate paths, which yield bare common_pb2.ConfigurationActivation objects rather than result wrappers. A module-level helper (is_open(activation) -> bool) may serve both shapes better than a property on one result class; that tradeoff is the main design question here.

Scope

  • Additive and independent — no change to request building or the wire format.
  • Unit tests for: open-ended record, bounded record, error/no-record case.
  • Update the cookbook's "still open" recipe to use it, replacing the raw HasField check.

Activity

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions