Skip to content

[management] remove context from store methods#4940

Merged
pascal-fischer merged 2 commits intomainfrom
fix/remove-context-from-store-methods
Dec 11, 2025
Merged

[management] remove context from store methods#4940
pascal-fischer merged 2 commits intomainfrom
fix/remove-context-from-store-methods

Conversation

@pascal-fischer
Copy link
Copy Markdown
Collaborator

@pascal-fischer pascal-fischer commented Dec 11, 2025

Describe your changes

Issue ticket number and link

Stack

Checklist

  • Is it a bug fix
  • Is a typo/documentation fix
  • Is a feature enhancement
  • It is a refactor
  • Created tests that fail without the change (if possible)

By submitting this pull request, you confirm that you have read and agree to the terms of the Contributor License Agreement.

Documentation

Select exactly one:

  • I added/updated documentation for this change
  • Documentation is not needed for this change (explain why)

Docs PR URL (required if "docs added" is checked)

Paste the PR link from https://github.com/netbirdio/docs here:

https://github.com/netbirdio/docs/pull/__

Summary by CodeRabbit

  • Refactor
    • Internal database transaction handling has been streamlined to rely on existing transaction context, reducing redundant context propagation.
    • This improves stability and consistency of database operations and may reduce transient errors during create/update flows.

✏️ Tip: You can customize this high-level summary in your review settings.

@coderabbitai
Copy link
Copy Markdown
Contributor

coderabbitai Bot commented Dec 11, 2025

Walkthrough

Removed explicit per-call context binding from many DB operations in management/server/store/sql_store.go, replacing WithContext(ctx) calls with context-free GORM operations so transactions rely on their existing context instead.

Changes

Cohort / File(s) Change Summary
Context handling refactor
management/server/store/sql_store.go
Replaced WithContext(ctx) database calls with context-free variants across multiple methods (e.g., GetAccountNetwork, GetPeerByPeerPubKey, SaveUserLastLogin, GetSetupKeyBySecret, IncrementSetupKeyUsage, AddPeerToAllGroup, AddPeerToAccount, IncrementNetworkSerial, UpdateAccountNetwork), shifting reliance to transaction-level context and adjusting error propagation accordingly.

Estimated code review effort

🎯 2 (Simple) | ⏱️ ~12 minutes

  • Attention areas:
    • Ensure transaction-level context covers timeouts/cancellation for each affected operation
    • Verify error classification/propagation (NotFound vs Internal) remains correct for callers
    • Review multi-step methods to confirm context continuity across sequential DB calls

Possibly related PRs

  • [management] cleanup logs #4933 — Modifies management/server/store/sql_store.go and addresses context handling scaffolding; closely related changes to how context is propagated in DB calls.

Suggested reviewers

  • crn4

Poem

🐇 I hopped through rows and queries with delight,
Took off the wraps of WithContext overnight,
Transactions hum, the calls now light,
A little hop, and everything's right. 🥕

Pre-merge checks and finishing touches

❌ Failed checks (1 warning)
Check name Status Explanation Resolution
Description check ⚠️ Warning The PR description is incomplete with empty 'Describe your changes' and 'Issue ticket number and link' sections, missing explanation for why documentation is not needed, and lacks substantive details about the changes. Fill in the 'Describe your changes' section with details about context removal, add issue/ticket reference, and explain why documentation is not needed for this refactoring change.
✅ Passed checks (2 passed)
Check name Status Explanation
Title check ✅ Passed The title accurately describes the main change: removing context from store methods in the management component, which aligns with the actual code modifications.
Docstring Coverage ✅ Passed No functions found in the changed files to evaluate docstring coverage. Skipping docstring coverage check.
✨ Finishing touches
  • 📝 Generate docstrings
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Post copyable unit tests in a comment
  • Commit unit tests in branch fix/remove-context-from-store-methods

📜 Recent review details

Configuration used: CodeRabbit UI

Review profile: CHILL

Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between 3f53c05 and de9ad77.

📒 Files selected for processing (1)
  • management/server/store/sql_store.go (10 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). (28)
  • GitHub Check: Management / Integration (amd64, sqlite)
  • GitHub Check: Management / Benchmark (API) (amd64, sqlite)
  • GitHub Check: Management / Benchmark (API) (amd64, postgres)
  • GitHub Check: Management / Unit (amd64, postgres)
  • GitHub Check: Management / Unit (amd64, sqlite)
  • GitHub Check: Management / Integration (amd64, postgres)
  • GitHub Check: Management / Unit (amd64, mysql)
  • GitHub Check: Signal / Unit (amd64)
  • GitHub Check: Client / Unit (386)
  • GitHub Check: Relay / Unit (386)
  • GitHub Check: Signal / Unit (386)
  • GitHub Check: Client (Docker) / Unit
  • GitHub Check: Client / Unit (amd64)
  • GitHub Check: Relay / Unit (amd64, -race)
  • GitHub Check: Management / Benchmark (amd64, postgres)
  • GitHub Check: Management / Benchmark (amd64, sqlite)
  • GitHub Check: Client / Unit
  • GitHub Check: Client / Unit
  • GitHub Check: Linux
  • GitHub Check: Darwin
  • GitHub Check: Windows
  • GitHub Check: Client / Unit
  • GitHub Check: JS / Lint
  • GitHub Check: release_ui_darwin
  • GitHub Check: release_ui
  • GitHub Check: release
  • GitHub Check: iOS / Build
  • GitHub Check: Android / Build

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: 1

Caution

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

⚠️ Outside diff range comments (1)
management/server/store/sql_store.go (1)

591-591: Inconsistency: WithContext(ctx) still present here.

This line still uses .WithContext(ctx), while all other changes in this PR remove it. This creates inconsistent behavior across the store methods.

Apply this diff to align with the other changes:

-	result := tx.WithContext(ctx).Take(&user, idQueryCondition, userID)
+	result := tx.Take(&user, idQueryCondition, userID)
📜 Review details

Configuration used: CodeRabbit UI

Review profile: CHILL

Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between 90e3b80 and 3f53c05.

📒 Files selected for processing (1)
  • management/server/store/sql_store.go (9 hunks)
🧰 Additional context used
🧬 Code graph analysis (1)
management/server/store/sql_store.go (7)
shared/management/http/api/types.gen.go (3)
  • Account (240-257)
  • SetupKey (1637-1682)
  • Group (462-481)
management/server/types/account.go (1)
  • Account (71-106)
shared/management/status/error.go (1)
  • Error (54-57)
management/server/types/setupkey.go (1)
  • SetupKey (33-59)
management/server/types/group.go (1)
  • Group (15-36)
client/firewall/nftables/manager_linux.go (1)
  • Create (56-76)
client/firewall/iptables/manager_linux.go (1)
  • Create (39-61)
⏰ 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). (25)
  • GitHub Check: Management / Unit (amd64, mysql)
  • GitHub Check: Relay / Unit (386)
  • GitHub Check: Management / Benchmark (API) (amd64, sqlite)
  • GitHub Check: Relay / Unit (amd64, -race)
  • GitHub Check: Management / Unit (amd64, sqlite)
  • GitHub Check: Management / Benchmark (API) (amd64, postgres)
  • GitHub Check: Management / Unit (amd64, postgres)
  • GitHub Check: Management / Integration (amd64, sqlite)
  • GitHub Check: Client / Unit (amd64)
  • GitHub Check: Client / Unit (386)
  • GitHub Check: Signal / Unit (amd64)
  • GitHub Check: Management / Benchmark (amd64, postgres)
  • GitHub Check: Management / Integration (amd64, postgres)
  • GitHub Check: Client (Docker) / Unit
  • GitHub Check: Management / Benchmark (amd64, sqlite)
  • GitHub Check: Client / Unit
  • GitHub Check: Client / Unit
  • GitHub Check: release
  • GitHub Check: release_ui_darwin
  • GitHub Check: Darwin
  • GitHub Check: Windows
  • GitHub Check: JS / Lint
  • GitHub Check: Linux
  • GitHub Check: Android / Build
  • GitHub Check: Client / Unit

Comment thread management/server/store/sql_store.go
@sonarqubecloud
Copy link
Copy Markdown

@pascal-fischer pascal-fischer merged commit abcbde2 into main Dec 11, 2025
40 checks passed
@pascal-fischer pascal-fischer deleted the fix/remove-context-from-store-methods branch December 11, 2025 20:45
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