Skip to content

Fix taxonomies import when filters already exist - #17358

Open
microstudi wants to merge 2 commits into
developfrom
fix/taxonomy-filter-import
Open

Fix taxonomies import when filters already exist#17358
microstudi wants to merge 2 commits into
developfrom
fix/taxonomy-filter-import

Conversation

@microstudi

@microstudi microstudi commented Jul 23, 2026

Copy link
Copy Markdown
Contributor

🎩 What? Why?

The rake task bin/rails decidim:taxonomies:import_plan imports filters created from the old categorization system. However there is a small bug and only imports the last filter defined.

For instance if you have JSON file defined like:

{
  "imported_taxonomies": {
    "Scopes": {
      "taxonomies": {...}
      "filters": [
        {
          "name": "Scopes filter",
          "components": [
            "gid://decidim-nyc/Decidim::Component/11"
          ]
        }
      ]
    },
    "Categories": {
      "taxonomies": {...}
      "filters": [
        {
          "name": "Categories filter",
          "components": [
            "gid://decidim-nyc/Decidim::Component/11"
          ]
        }
      ]
    }

  }
}

Only the last filter will be imported in the Component 11.
This fixes the situation by ensuring to import whatever configuration already available.

📌 Related Issues

Link your PR to an issue

  • Related to #?
  • Fixes #?

Testing

This probably only happens on situations where you customiza the JSON plan file created from a migration from version 29 to 30.

📷 Screenshots

Please add screenshots of the changes you are proposing
N/A

♥️ Thank you!

Summary by CodeRabbit

  • Bug Fixes
    • Preserved existing taxonomy filters when importing additional filters.
    • Prevented duplicate taxonomy filter entries during repeated imports.
    • Ensured repeated imports produce consistent results.

Copilot AI review requested due to automatic review settings July 23, 2026 15:50
@coderabbitai

coderabbitai Bot commented Jul 23, 2026

Copy link
Copy Markdown
Contributor

Review Change Stack

No actionable comments were generated in the recent review. 🎉

ℹ️ Recent review info
⚙️ Run configuration

Configuration used: Path: .coderabbit.yaml

Review profile: CHILL

Plan: Pro Plus

Run ID: 8a006191-9259-4919-80da-1384edff6705

📥 Commits

Reviewing files that changed from the base of the PR and between edf59cf and 46a7425.

📒 Files selected for processing (2)
  • decidim-core/lib/decidim/maintenance/taxonomy_importer.rb
  • decidim-core/spec/lib/maintenance/taxonomy_importer_spec.rb

📝 Walkthrough

Walkthrough

The taxonomy importer now preserves existing component taxonomy filter IDs, appends imported IDs only when missing, and verifies that repeated imports do not duplicate filters.

Changes

Taxonomy filter import

Layer / File(s) Summary
Incremental taxonomy filter settings
decidim-core/lib/decidim/maintenance/taxonomy_importer.rb, decidim-core/spec/lib/maintenance/taxonomy_importer_spec.rb
The importer retains existing taxonomy_filters, appends the imported filter ID only when absent, and tests preservation and idempotency across repeated imports.

Estimated code review effort: 2 (Simple) | ~10 minutes

🚥 Pre-merge checks | ✅ 5
✅ Passed checks (5 passed)
Check name Status Explanation
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title check ✅ Passed The title clearly summarizes the main fix: importing taxonomies when filters already exist.
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 docstrings
  • Create stacked PR
  • Commit on current branch
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Commit unit tests in branch fix/taxonomy-filter-import

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.

@microstudi microstudi changed the title fix filter import when filters already exist Fix filter import when filters already exist Jul 23, 2026
@request-info

request-info Bot commented Jul 23, 2026

Copy link
Copy Markdown

It seems like you did not give us much information about what you are trying to do here. We would appreciate it if you could provide us with more info about this issue/PR!

@microstudi microstudi changed the title Fix filter import when filters already exist Fix taxonomies import when filters already exist Jul 23, 2026
@github-actions github-actions Bot added module: core type: fix PRs that implement a fix for a bug labels Jul 23, 2026
github-actions[bot]
github-actions Bot previously approved these changes Jul 23, 2026

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

Updates the taxonomy maintenance importer so importing taxonomy filters into components no longer overwrites pre-existing taxonomy_filters, addressing cases where components already have filters configured.

Changes:

  • Preserve and extend existing component settings[:taxonomy_filters] during import instead of replacing it.
  • Avoid duplicating the same taxonomy filter ID in the component settings.

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

Comment thread decidim-core/lib/decidim/maintenance/taxonomy_importer.rb
Comment thread decidim-core/lib/decidim/maintenance/taxonomy_importer.rb
Copilot AI review requested due to automatic review settings July 23, 2026 16:03

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

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

Comments suppressed due to low confidence (1)

decidim-core/lib/decidim/maintenance/taxonomy_importer.rb:91

  • settings[:taxonomy_filters] may already contain integer IDs (e.g. some specs set taxonomy_filters: [taxonomy_filter.id]). In that case, the current include?(filter.id.to_s) check won’t detect an existing filter (123 vs "123") and will append a duplicate entry. Normalizing existing values to strings (and uniquing) before appending avoids mixed-type duplicates and makes the method idempotent across input types.
              settings = component.settings.to_h
              settings[:taxonomy_filters] ||= []
              settings[:taxonomy_filters] << filter.id.to_s unless settings[:taxonomy_filters].include?(filter.id.to_s)
              component.update!(settings:)

@microstudi
microstudi marked this pull request as ready for review July 23, 2026 16:11
@microstudi microstudi mentioned this pull request Jul 23, 2026
15 tasks
@alecslupu alecslupu self-assigned this Jul 30, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

module: core type: fix PRs that implement a fix for a bug

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants