Skip to content

[management] fix fetching of missing settings in GetAccount call#6800

Open
dmitri-netbird wants to merge 4 commits into
mainfrom
dmitri-fix-account-settings
Open

[management] fix fetching of missing settings in GetAccount call#6800
dmitri-netbird wants to merge 4 commits into
mainfrom
dmitri-fix-account-settings

Conversation

@dmitri-netbird

@dmitri-netbird dmitri-netbird commented Jul 16, 2026

Copy link
Copy Markdown
Contributor

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)
  • This change does not modify the public API, gRPC protocols, functionality behavior, CLI / service flags, or introduce a new feature — OR I have discussed it with the NetBird team beforehand (link the issue / Slack thread in the description). See CONTRIBUTING.md.

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/__


View with Codesmith Autofix with Codesmith
Need help on this PR? Tag /codesmith with what you need. Autofix is disabled.

Summary by CodeRabbit

  • Bug Fixes

    • Ensure account settings are fully preserved through save/load, including automatic update and peer exposure preferences.
  • Tests

    • Added coverage to verify account settings remain unchanged after database persistence and retrieval (skipped on Windows due to SQLite limitations).
    • Introduced deterministic test-data population helpers to reliably set struct fields for deeper settings verification.

Signed-off-by: Dmitri Dolguikh <dmitri.external@netbird.io>
@dmitri-netbird dmitri-netbird changed the title fix fetching of missing settings in GetAccount call [management] fix fetching of missing settings in GetAccount call Jul 16, 2026
@coderabbitai

coderabbitai Bot commented Jul 16, 2026

Copy link
Copy Markdown
Contributor

Review Change Stack

Caution

Review failed

An error occurred during the review process. Please try again later.

📝 Walkthrough

Walkthrough

PostgreSQL account retrieval now includes auto-update and peer-exposure settings. A reflection-based helper populates deterministic struct values, and a store test verifies account settings survive save-and-retrieve operations.

Changes

Account settings persistence

Layer / File(s) Summary
Deterministic test field population
shared/testing_helpers/populate_fields.go
Adds configurable reflection-based population for exported fields, nested structs, slices, custom types, and skipped tags.
PostgreSQL settings retrieval
management/server/store/sql_store.go
Extends getAccountPgx to select, scan, and assign auto-update and peer-exposure settings, including JSON group data.
Account settings round-trip validation
management/server/store/sql_store_test.go
Adds a non-Windows test that populates settings, saves and reloads an account, and verifies deep equality.

Estimated code review effort: 3 (Moderate) | ~20 minutes

Possibly related PRs

Suggested reviewers: braginini

🚥 Pre-merge checks | ✅ 4 | ❌ 1

❌ Failed checks (1 warning)

Check name Status Explanation Resolution
Description check ⚠️ Warning Required sections are mostly empty: no change summary, no issue ticket, and no stack details; the docs choice also lacks an explanation. Add a short change summary, the issue ticket/link, the stack/branch info, and a brief explanation for why documentation is not needed.
✅ Passed checks (4 passed)
Check name Status Explanation
Title check ✅ Passed The title clearly describes the GetAccount settings fix and matches the change.
Docstring Coverage ✅ Passed No functions found in the changed files to evaluate docstring coverage. Skipping docstring coverage check.
Linked Issues check ✅ Passed Check skipped because no linked issues were found for this pull request.
Out of Scope Changes check ✅ Passed Check skipped because no linked issues were found for this pull request.
✨ Finishing Touches
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Commit unit tests in branch dmitri-fix-account-settings

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.

…ttings

Signed-off-by: Dmitri Dolguikh <dmitri.external@netbird.io>
@github-actions

github-actions Bot commented Jul 16, 2026

Copy link
Copy Markdown

Release artifacts

Built for PR head 15bc9b4 in workflow run #16811.

Artifact Link
All release artifacts Download
Linux packages Download
Windows packages Download
macOS packages Download
UI artifacts Download
UI macOS artifacts Download

GHCR images (amd64)

This comment is updated by the Release workflow. Artifact links expire according to the workflow retention policy.

@coderabbitai coderabbitai Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Actionable comments posted: 1

🧹 Nitpick comments (1)
management/server/store/sql_store_test.go (1)

345-346: 📐 Maintainability & Code Quality | 🔵 Trivial | 💤 Low value

Check errors returned by json.Marshal.

The err returned by both json.Marshal calls is currently unhandled. Asserting that no error occurs prevents linter warnings (e.g., ineffassign, errcheck) and ensures test reliability in case serialization fails.

♻️ Proposed refactor
 		settingJson, err := json.Marshal(settings)
+		assert.NoError(t, err)
 		dbSettingJson, err := json.Marshal(accountFromDb.Settings)
+		assert.NoError(t, err)
🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

In `@management/server/store/sql_store_test.go` around lines 345 - 346, Handle the
errors returned by both json.Marshal calls in the test, asserting each error is
nil before using the serialized values. Update the test code around settingJson
and dbSettingJson so neither marshal result is ignored and serialization
failures fail the test clearly.
🤖 Prompt for all review comments with AI agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

Inline comments:
In `@shared/testing_helpers/populate_fields.go`:
- Around line 71-74: Update the Slice case in the field-population logic to
capture and return any error from p.setNonZero(s.Index(0)) before setting the
slice. Preserve the existing slice construction and assignment behavior when
element population succeeds, while ensuring unsupported element types fail
explicitly.

---

Nitpick comments:
In `@management/server/store/sql_store_test.go`:
- Around line 345-346: Handle the errors returned by both json.Marshal calls in
the test, asserting each error is nil before using the serialized values. Update
the test code around settingJson and dbSettingJson so neither marshal result is
ignored and serialization failures fail the test clearly.
🪄 Autofix (Beta)

Fix all unresolved CodeRabbit comments on this PR:

  • Push a commit to this branch (recommended)
  • Create a new PR with the fixes

ℹ️ Review info
⚙️ Run configuration

Configuration used: Path: .coderabbit.yaml

Review profile: CHILL

Plan: Pro

Run ID: 87ff71b7-772e-4868-bad9-40feaea3aa1b

📥 Commits

Reviewing files that changed from the base of the PR and between d15830a and 742de8a.

📒 Files selected for processing (3)
  • management/server/store/sql_store.go
  • management/server/store/sql_store_test.go
  • shared/testing_helpers/populate_fields.go

Comment thread shared/testing_helpers/populate_fields.go
pascal-fischer
pascal-fischer previously approved these changes Jul 16, 2026
Signed-off-by: Dmitri Dolguikh <dmitri.external@netbird.io>
Signed-off-by: Dmitri Dolguikh <dmitri.external@netbird.io>
@sonarqubecloud

Copy link
Copy Markdown

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