Skip to content

[DaC] [Bug] Raw rule loading fails when deprecated and active rules share a name#6309

Open
eric-forte-elastic wants to merge 1 commit into
mainfrom
6308-dac-bug-raw-rule-loading-fails-when-deprecated-and-active-rules-share-a-name
Open

[DaC] [Bug] Raw rule loading fails when deprecated and active rules share a name#6309
eric-forte-elastic wants to merge 1 commit into
mainfrom
6308-dac-bug-raw-rule-loading-fails-when-deprecated-and-active-rules-share-a-name

Conversation

@eric-forte-elastic

@eric-forte-elastic eric-forte-elastic commented Jun 18, 2026

Copy link
Copy Markdown
Contributor

Pull Request

Issue link(s):

Resolves #6308

Summary - What I changed

Fixes --load-rule-loading failures when an active rule and a deprecated rule share the same name.

RawRuleCollection now separates deprecated raw rules into collection.deprecated, matching the active/deprecated split already used by RuleCollection. This preserves the intended DaC behavior of using active local rules for path preservation while allowing deprecated stubs to reuse names without colliding.

RawRuleCollection is only used in existing DaC commands. These logical paths are the ones impacted by this change.

  • kibana export-rules --load-rule-loading
  • import-rules-to-repo --load-rule-loading

How To Test

Run the kibana export DaC command with the --load-rule-loading flag. The error would fire when building the local rule directory map keying off of rule names, so one does not need to have rules in the specified testing Kibana instance to see the error prior, or see the fix.

The command should now not throw an error.

E.g.

python -m detection_rules kibana --space default export-rules -d rules/ -ac -e --load-rule-loading  --skip-errors
image

Checklist

  • Added a label for the type of pr: bug, enhancement, schema, maintenance, Rule: New, Rule: Deprecation, Rule: Tuning, Hunt: New, or Hunt: Tuning so guidelines can be generated
  • Added the meta:rapid-merge label if planning to merge within 24 hours
  • Secret and sensitive material has been managed correctly
  • Automated testing was updated or added to match the most common scenarios
  • Documentation and comments were added for features that require explanation

Contributor checklist

@eric-forte-elastic eric-forte-elastic self-assigned this Jun 18, 2026
@eric-forte-elastic eric-forte-elastic added bug Something isn't working python Internal python for the repository labels Jun 18, 2026
@github-actions

Copy link
Copy Markdown
Contributor

Bug - Guidelines

These guidelines serve as a reminder set of considerations when addressing a bug in the code.

Documentation and Context

  • Provide detailed documentation (description, screenshots, reproducing the bug, etc.) of the bug if not already documented in an issue.
  • Include additional context or details about the problem.
  • Ensure the fix includes necessary updates to the release documentation and versioning.

Code Standards and Practices

  • Code follows established design patterns within the repo and avoids duplication.
  • Ensure that the code is modular and reusable where applicable.

Testing

  • New unit tests have been added to cover the bug fix or edge cases.
  • Existing unit tests have been updated to reflect the changes.
  • Provide evidence of testing and detecting the bug fix (e.g., test logs, screenshots).
  • Validate that any rules affected by the bug are correctly updated.
  • Ensure that performance is not negatively impacted by the changes.
  • Verify that any release artifacts are properly generated and tested.
  • Conducted system testing, including fleet, import, and create APIs (e.g., run make test-cli, make test-remote-cli, make test-hunting-cli)

Additional Checks

  • Verify that the bug fix works across all relevant environments (e.g., different OS versions).
  • Confirm that the proper version label is applied to the PR patch, minor, major.

Copilot AI 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.

Pull request overview

Fixes DaC --load-rule-loading failures caused by name collisions when an active rule and a deprecated stub share the same name, by splitting raw-loaded deprecated rules into a separate namespace (mirroring RuleCollection’s active/deprecated structure).

Changes:

  • Added RawDeprecatedCollection and introduced RawRuleCollection.deprecated to store raw deprecated rules separately.
  • Updated RawRuleCollection loading/add logic to route deprecated rules (by metadata.maturity == "deprecated") into the deprecated collection, preventing name-map collisions.
  • Bumped package version to 1.6.54.

Reviewed changes

Copilot reviewed 2 out of 2 changed files in this pull request and generated 1 comment.

File Description
pyproject.toml Bumps the project version for the bugfix release.
detection_rules/rule_loader.py Splits raw rule loading into active vs deprecated collections to avoid rule-name collisions during DaC raw loading.

Comment on lines 281 to 333
@@ -288,10 +316,20 @@ def add_rule(self, rule: DictRule) -> None:
self.name_map[rule.name] = rule
self.rules.append(rule)

def add_deprecated_rule(self, rule: DictRule) -> None:
"""Add a deprecated rule to the collection."""
self._assert_new(rule, is_deprecated=True)
self.deprecated.id_map[rule.id] = rule
self.deprecated.name_map[rule.name] = rule
self.deprecated.rules.append(rule)

def load_dict(self, obj: dict[str, Any], path: Path | None = None) -> DictRule:
"""Load a rule from a dictionary."""
rule = DictRule(contents=obj, path=path)
self.add_rule(rule)
if self.is_deprecated_rule(rule):
self.add_deprecated_rule(rule)
else:
self.add_rule(rule)
return rule
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

backport: auto bug Something isn't working detections-as-code patch python Internal python for the repository

Projects

None yet

Development

Successfully merging this pull request may close these issues.

[DaC] [Bug] Raw rule loading fails when deprecated and active rules share a name

2 participants