Skip to content

feat: Add IS_NULL and IS_NOT_NULL operators for rule null handling #1895

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Draft
wants to merge 2 commits into
base: main
Choose a base branch
from

Conversation

Copilot
Copy link
Contributor

@Copilot Copilot AI commented Jul 24, 2025

Overview

This PR adds comprehensive null handling support to Maintainerr rules, allowing users to explicitly match on null values and fixing the boolean logic bug identified in PR #1857.

Key Changes

🐛 Boolean Logic Fix

Fixed the boolean logic bug from PR #1857:

// Before (broken):
if ((firstVal !== undefined || null) && (secondVal !== undefined || null)) {
    // || null always evaluates to null (falsy), breaking the logic
}

// After (fixed):
if ((firstVal !== undefined && firstVal !== null) && (secondVal !== undefined && secondVal !== null)) {
    // Proper null checking
}

✨ New Null Operators

Added two new operators to RulePossibility enum:

  • IS_NULL (value: 18) - Matches values that are explicitly null
  • IS_NOT_NULL (value: 19) - Matches values that are not null

🔧 Smart Processing Logic

Enhanced rule execution to allow null values for null-specific operators while preserving existing behavior:

const allowsNullValues = [RulePossibility.IS_NULL, RulePossibility.IS_NOT_NULL].includes(rule.action);
const hasValidValues = allowsNullValues || 
  ((firstVal !== undefined && firstVal !== null) &&
   (secondVal !== undefined && secondVal !== null));

🎯 New Rule Type

Added RuleType.NULL (ID: 5) specifically for null operations, ensuring type safety and proper UI integration.

Use Cases

Users can now create rules like:

- Find unrated movies: "Plex rating IS_NULL"
- Find watched content: "Last viewed date IS_NOT_NULL"  
- Find unrequested media: "Overseerr request date IS_NULL"
- Find content with metadata: "Movie description IS_NOT_NULL"

Testing

  • 22 new tests covering all null handling scenarios
  • 174 total tests passing across all rule modules
  • Backwards compatibility verified - all existing functionality preserved
  • Edge cases covered - null vs undefined vs empty string distinctions

Backwards Compatibility

This is a non-breaking change:

  • All existing rules continue to work unchanged
  • New operators are additive functionality
  • Existing null-skipping behavior preserved for non-null operators

Example Usage

// New null-specific operators
ruleComparator.doRuleAction(null, null, RulePossibility.IS_NULL);        // true
ruleComparator.doRuleAction('text', null, RulePossibility.IS_NULL);      // false
ruleComparator.doRuleAction(null, null, RulePossibility.IS_NOT_NULL);    // false
ruleComparator.doRuleAction('text', null, RulePossibility.IS_NOT_NULL);  // true

// Existing operators still work
ruleComparator.doRuleAction('test', 'test', RulePossibility.EQUALS);     // true

Fixes #1894.


💬 Share your feedback on Copilot coding agent for the chance to win a $200 gift card! Click here to start the survey.

- Fixed boolean logic bug from PR #1857 (line 201-203)
- Added IS_NULL and IS_NOT_NULL operators to RulePossibility enum
- Created NULL rule type for null-specific operations
- Updated rule comparison logic to handle null values appropriately
- Added comprehensive tests covering all null handling scenarios
- Maintained backwards compatibility with existing rules

Co-authored-by: benscobie <944312+benscobie@users.noreply.github.com>
@Copilot Copilot AI changed the title [WIP] [copilot] Add support for null handling in rules feat: Add IS_NULL and IS_NOT_NULL operators for rule null handling Jul 24, 2025
@Copilot Copilot AI requested a review from benscobie July 24, 2025 22:59
Copilot finished work on behalf of benscobie July 24, 2025 22:59
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.

[copilot] Add support for null handling in rules
2 participants