Skip to content

fix ProfileDataField.UnmarshalJSON to accept null#645

Merged
YakirOren merged 2 commits intomainfrom
fix/profile-data-null
May 7, 2026
Merged

fix ProfileDataField.UnmarshalJSON to accept null#645
YakirOren merged 2 commits intomainfrom
fix/profile-data-null

Conversation

@YakirOren
Copy link
Copy Markdown
Contributor

@YakirOren YakirOren commented May 7, 2026

Summary by CodeRabbit

  • Bug Fixes
    • Profile data configurations now correctly handle null values in JSON and BSON data formats, improving compatibility with existing data structures.

Copilot AI review requested due to automatic review settings May 7, 2026 07:16
@coderabbitai
Copy link
Copy Markdown

coderabbitai Bot commented May 7, 2026

Review Change Stack

Important

Review skipped

Auto incremental reviews are disabled on this repository.

Please check the settings in the CodeRabbit UI or the .coderabbit.yaml file in this repository. To trigger a single review, invoke the @coderabbitai review command.

⚙️ Run configuration

Configuration used: Organization UI

Review profile: CHILL

Plan: Pro

Run ID: 9c44d3e7-9264-4fb7-b729-7c4efb12ef7d

You can disable this status message by setting the reviews.review_status to false in the CodeRabbit configuration file.

Use the checkbox below for a quick retry:

  • 🔍 Trigger review
📝 Walkthrough

Walkthrough

The PR modifies ProfileDataField to accept null values in JSON and BSON unmarshalling operations. Previously, null inputs were treated as errors; now they return success without modifying the struct, leaving fields at their zero values (All == false, Patterns == nil). A test verifies this new permissive behavior.

Changes

ProfileDataField Null Handling

Layer / File(s) Summary
Core Serialization Changes
armotypes/runtimerule.go
UnmarshalJSON and UnmarshalBSONValue now return nil when encountering JSON null and BSON null respectively, instead of treating them as errors.
Test Updates
armotypes/runtimerule_profile_data_test.go
New test TestProfileDataField_UnmarshalJSON_AcceptsNull verifies that null JSON input is accepted and results in zero-valued struct fields.

Estimated code review effort

🎯 2 (Simple) | ⏱️ ~10 minutes

Possibly related PRs

  • armosec/armoapi-go#642: Introduces ProfileDataField serialization codecs; this PR extends null-handling behavior for those codecs.

Poem

A rabbit hops through schemas bright,
Where nulls once caused a parsing blight,
Now null's a friend, not foe or fear,
Fields return to zero, crystal clear! 🐰✨

🚥 Pre-merge checks | ✅ 4 | ❌ 1

❌ Failed checks (1 warning)

Check name Status Explanation Resolution
Docstring Coverage ⚠️ Warning Docstring coverage is 0.00% which is insufficient. The required threshold is 80.00%. Write docstrings for the functions missing them to satisfy the coverage threshold.
✅ Passed checks (4 passed)
Check name Status Explanation
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title check ✅ Passed The title accurately and concisely describes the main change: fixing ProfileDataField.UnmarshalJSON to handle null values, which is exactly what the changeset implements.
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.

✏️ Tip: You can configure your own custom pre-merge checks in the settings.

✨ Finishing Touches
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Commit unit tests in branch fix/profile-data-null

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

@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.

🧹 Nitpick comments (1)
armotypes/runtimerule_profile_data_test.go (1)

92-98: ⚡ Quick win

Add a parallel BSON null test to cover the symmetric UnmarshalBSONValue change.

TestProfileDataField_UnmarshalJSON_AcceptsNull covers the JSON path, but the bsontype.Null early-return added to UnmarshalBSONValue has no test. A BSON null can arrive from MongoDB when a document field is explicitly set to null.

🧪 Suggested test
func TestProfileDataField_UnmarshalBSONValue_AcceptsNull(t *testing.T) {
	var f ProfileDataField
	err := f.UnmarshalBSONValue(bsontype.Null, nil)
	assert.NoError(t, err)
	assert.False(t, f.All)
	assert.Nil(t, f.Patterns)
}
🤖 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 `@armotypes/runtimerule_profile_data_test.go` around lines 92 - 98, Add a
parallel BSON null unit test to cover the new bsontype.Null early-return in
UnmarshalBSONValue: create TestProfileDataField_UnmarshalBSONValue_AcceptsNull
that declares var f ProfileDataField, calls f.UnmarshalBSONValue(bsontype.Null,
nil), asserts no error, asserts f.All is false and f.Patterns is nil; this
mirrors TestProfileDataField_UnmarshalJSON_AcceptsNull to ensure BSON nulls from
MongoDB are handled.
🤖 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.

Nitpick comments:
In `@armotypes/runtimerule_profile_data_test.go`:
- Around line 92-98: Add a parallel BSON null unit test to cover the new
bsontype.Null early-return in UnmarshalBSONValue: create
TestProfileDataField_UnmarshalBSONValue_AcceptsNull that declares var f
ProfileDataField, calls f.UnmarshalBSONValue(bsontype.Null, nil), asserts no
error, asserts f.All is false and f.Patterns is nil; this mirrors
TestProfileDataField_UnmarshalJSON_AcceptsNull to ensure BSON nulls from MongoDB
are handled.

ℹ️ Review info
⚙️ Run configuration

Configuration used: Organization UI

Review profile: CHILL

Plan: Pro

Run ID: a5b768ca-405e-4f37-aee2-ed1427099532

📥 Commits

Reviewing files that changed from the base of the PR and between fc99b93 and 353fd60.

📒 Files selected for processing (2)
  • armotypes/runtimerule.go
  • armotypes/runtimerule_profile_data_test.go

Copy link
Copy Markdown
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

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

Pull request overview

This PR updates ProfileDataField decoding to tolerate null values during JSON and BSON unmarshalling, aligning it with optional/absent semantics that can appear in stored documents or payloads.

Changes:

  • Allow ProfileDataField.UnmarshalJSON to accept null without error.
  • Allow ProfileDataField.UnmarshalBSONValue to accept BSON Null without error.
  • Update the unit test to expect null JSON unmarshalling to succeed.

Reviewed changes

Copilot reviewed 2 out of 2 changed files in this pull request and generated 3 comments.

File Description
armotypes/runtimerule.go Adjusts JSON and BSON unmarshalling for ProfileDataField to accept null inputs.
armotypes/runtimerule_profile_data_test.go Updates JSON null unmarshalling test to expect success and verify resulting state.

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

Comment thread armotypes/runtimerule.go
Comment thread armotypes/runtimerule.go
Comment thread armotypes/runtimerule_profile_data_test.go
@github-actions
Copy link
Copy Markdown

github-actions Bot commented May 7, 2026

Coverage Report for CI Build 25481752728

Warning

No base build found for commit fc99b93 on main.
Coverage changes can't be calculated without a base build.
If a base build is processing, this comment will update automatically when it completes.

Coverage: 43.199%

Details

  • Patch coverage: 2 uncovered changes across 1 file (2 of 4 lines covered, 50.0%).

Uncovered Changes

File Changed Covered %
armotypes/runtimerule.go 4 2 50.0%

Coverage Regressions

Requires a base build to compare against. How to fix this →


Coverage Stats

Coverage Status
Relevant Lines: 4632
Covered Lines: 2001
Line Coverage: 43.2%
Coverage Strength: 5.78 hits per line

💛 - Coveralls

@YakirOren YakirOren merged commit 1d22bb8 into main May 7, 2026
3 checks passed
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.

3 participants