Skip to content
This repository was archived by the owner on Jan 23, 2026. It is now read-only.

client: exclude None selector from match check#624

Merged
mangelajo merged 2 commits intojumpstarter-dev:mainfrom
bennyz:exclude-non-selector
Sep 19, 2025
Merged

client: exclude None selector from match check#624
mangelajo merged 2 commits intojumpstarter-dev:mainfrom
bennyz:exclude-non-selector

Conversation

@bennyz
Copy link
Copy Markdown
Member

@bennyz bennyz commented Sep 19, 2025

if the selector is None, use the existing selector

Summary by CodeRabbit

  • Bug Fixes
    • Corrected lease selection to reuse existing leases when no selector is specified, preventing unintended new leases.
    • Preserved behavior when a selector is provided: a new lease is created only if it differs from the existing one.
    • Reduced noise in logs by showing selector mismatch warnings only when a selector is explicitly set.

if the selector is None, use the existing selector

Signed-off-by: Benny Zlotnik <bzlotnik@redhat.com>
@netlify
Copy link
Copy Markdown

netlify Bot commented Sep 19, 2025

Deploy Preview for jumpstarter-docs ready!

Name Link
🔨 Latest commit d052b5b
🔍 Latest deploy log https://app.netlify.com/projects/jumpstarter-docs/deploys/68cd54aed1e3c800083c7aa6
😎 Deploy Preview https://deploy-preview-624--jumpstarter-docs.netlify.app
📱 Preview on mobile
Toggle QR Code...

QR Code

Use your smartphone camera to open QR code link.

To edit notification comments on pull requests, go to your Netlify project configuration.

@coderabbitai
Copy link
Copy Markdown
Contributor

coderabbitai Bot commented Sep 19, 2025

Walkthrough

Introduces a conditional guard in Lease.request_async so selector comparison and mismatch handling only occur when a selector is explicitly provided; otherwise, an existing lease is reused. Logging about selector mismatches is now conditional on an explicitly provided selector. No public API signatures changed.

Changes

Cohort / File(s) Summary
Lease selector guard
packages/jumpstarter/jumpstarter/client/lease.py
Gate selector comparison on non-None self.selector; reuse existing lease when no selector is provided; warn and recreate only when an explicit selector mismatches; unchanged behavior when selectors match; logging limited to explicit-selector cases.

Sequence Diagram(s)

sequenceDiagram
  participant Caller
  participant Lease as Lease.request_async
  participant Store as LeaseStore

  Caller->>Lease: request_async(selector?)
  Lease->>Store: get existing_lease
  alt selector is provided (not None)
    alt existing_lease exists and selector matches
      Lease-->>Caller: reuse existing lease
    else existing_lease exists and selector mismatches
      Note over Lease: Log warning (selector mismatch)
      Lease->>Store: create new lease
      Lease-->>Caller: return new lease
    end
  else no selector provided (None)
    alt existing_lease exists
      Lease-->>Caller: reuse existing lease
    else no existing_lease
      Lease->>Store: create new lease
      Lease-->>Caller: return new lease
    end
  end
Loading

Estimated code review effort

🎯 2 (Simple) | ⏱️ ~10 minutes

Possibly related PRs

Suggested labels

backport release-0.7

Suggested reviewers

  • mangelajo

Poem

A rabbit reviewed leases with care,
“Compare when asked, else leave it there.”
With whiskers a-twitch and logs less loud,
Reuse the burrow, don’t build a crowd.
Hop-hop—selectors match? We’re set!
Mismatch? New warren—quick as a jet. 🐇

Pre-merge checks and finishing touches

✅ Passed checks (3 passed)
Check name Status Explanation
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title Check ✅ Passed The title "client: exclude None selector from match check" is concise, uses a clear scope prefix, and directly describes the primary change in the PR (ignoring None selectors so the existing selector is reused). It accurately reflects the intent and is specific enough for reviewers to understand the main change without extraneous detail.
Docstring Coverage ✅ Passed Docstring coverage is 100.00% which is sufficient. The required threshold is 80.00%.
✨ Finishing touches
  • 📝 Generate Docstrings
🧪 Generate unit tests
  • Create PR with unit tests
  • Post copyable unit tests in a comment

Tip

👮 Agentic pre-merge checks are now available in preview!

Pro plan users can now enable pre-merge checks in their settings to enforce checklists before merging PRs.

  • Built-in checks – Quickly apply ready-made checks to enforce title conventions, require pull request descriptions that follow templates, validate linked issues for compliance, and more.
  • Custom agentic checks – Define your own rules using CodeRabbit’s advanced agentic capabilities to enforce organization-specific policies and workflows. For example, you can instruct CodeRabbit’s agent to verify that API documentation is updated whenever API schema files are modified in a PR. Note: Upto 5 custom checks are currently allowed during the preview period. Pricing for this feature will be announced in a few weeks.

Please see the documentation for more information.

Example:

reviews:
  pre_merge_checks:
    custom_checks:
      - name: "Undocumented Breaking Changes"
        mode: "warning"
        instructions: |
          Pass/fail criteria: All breaking changes to public APIs, CLI flags, environment variables, configuration keys, database schemas, or HTTP/GraphQL endpoints must be documented in the "Breaking Change" section of the PR description and in CHANGELOG.md. Exclude purely internal or private changes (e.g., code not exported from package entry points or explicitly marked as internal).

Please share your feedback with us on this Discord post.


Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share

Comment @coderabbitai help to get the list of available commands and usage tips.

Copy link
Copy Markdown
Contributor

@coderabbitai coderabbitai Bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Actionable comments posted: 0

Caution

Some comments are outside the diff and can’t be posted inline due to platform limitations.

⚠️ Outside diff range comments (1)
packages/jumpstarter/jumpstarter/client/lease.py (1)

100-102: Reject creating a lease when selector is None — raise LeaseError before CreateLease

config.lease() allows selector=None and that None currently flows into Lease._create(), which calls ClientService.CreateLease(client_pb2.Lease(selector=selector)) — passing None will fail. Either validate/require a non-None selector at the callsite or guard in Lease.request_async before calling _create().

Suggested change (applies at packages/jumpstarter/jumpstarter/client/lease.py around lines 99–102):

-        else:
-            await self._create()
+        else:
+            if self.selector is None:
+                raise LeaseError(
+                    "selector must be provided to create a new lease when no existing lease is set"
+                )
+            await self._create()

Also reconcile the API mismatch: packages/jumpstarter/jumpstarter/config/client.py exposes lease(selector: str | None = None) but lease_async and Lease expect a non-None selector — either require selector upstream or convert/validate earlier.

🧹 Nitpick comments (3)
packages/jumpstarter/jumpstarter/client/lease.py (3)

33-33: Type should allow None for selector.

Runtime now treats None as meaningful; the annotation still says str. Update to reflect API and avoid type-checker noise.

-    selector: str
+    selector: str | None

79-86: Document None‑selector semantics in the docstring.

Clarify behavior for callers to prevent misuse.

         """Request a lease, or verifies a lease which was already created.
 
         :return: lease
         :rtype: Lease
         :raises LeaseError: if lease is unsatisfiable
         :raises LeaseError: if lease is not pending
         :raises TimeoutError: if lease is not ready after timeout
+        Note: If selector is None and a lease name is provided, the existing lease's selector is kept.
+        If selector is None and no lease name is provided, creating a new lease is not allowed.
         """

87-102: Add tests for None‑selector flow.

Cover:

  • existing lease name set + selector=None → reuse, no warning, no create
  • existing lease name set + selector=equal → reuse
  • existing lease name set + selector=different → warning + new lease
  • no existing lease name + selector=None → raises LeaseError (if you adopt the guard)

I can add async unit tests with a stubbed ClientService; say the word.

📜 Review details

Configuration used: CodeRabbit UI

Review profile: CHILL

Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between f04c65d and f9561b0.

📒 Files selected for processing (1)
  • packages/jumpstarter/jumpstarter/client/lease.py (1 hunks)
⏰ Context from checks skipped due to timeout of 90000ms. You can increase the timeout in your CodeRabbit configuration to a maximum of 15 minutes (900000ms). (11)
  • GitHub Check: build
  • GitHub Check: pytest-matrix (ubuntu-24.04, 3.13)
  • GitHub Check: pytest-matrix (macos-15, 3.11)
  • GitHub Check: pytest-matrix (ubuntu-24.04, 3.12)
  • GitHub Check: pytest-matrix (macos-15, 3.13)
  • GitHub Check: pytest-matrix (macos-15, 3.12)
  • GitHub Check: pytest-matrix (ubuntu-24.04, 3.11)
  • GitHub Check: e2e
  • GitHub Check: Redirect rules - jumpstarter-docs
  • GitHub Check: Header rules - jumpstarter-docs
  • GitHub Check: Pages changed - jumpstarter-docs
🔇 Additional comments (1)
packages/jumpstarter/jumpstarter/client/lease.py (1)

90-99: LGTM: mismatch check gated on explicit selector.

This matches the PR intent and avoids spurious re-leasing when selector is None.

@mangelajo mangelajo merged commit c119f82 into jumpstarter-dev:main Sep 19, 2025
18 checks passed
@jumpstarter-backport-bot
Copy link
Copy Markdown

Successfully created backport PR for release-0.7:

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

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants