Skip to content

Fix: Merge subgroups when inserting existing rows_as_columns links#316

Open
bioinfbloke wants to merge 1 commit intomainfrom
bugfix/mdvproject-fix
Open

Fix: Merge subgroups when inserting existing rows_as_columns links#316
bioinfbloke wants to merge 1 commit intomainfrom
bugfix/mdvproject-fix

Conversation

@bioinfbloke
Copy link
Contributor

@bioinfbloke bioinfbloke commented Jan 15, 2026

When merging MDV projects, insert_link() was overwriting existing
rows_as_columns links with empty subgroups, causing loss of subgroup
definitions during project merges.

Now checks if a rows_as_columns link already exists and merges the
subgroups dictionaries instead of overwriting, preserving existing
subgroups while allowing new ones to be added.

Summary by CodeRabbit

  • Bug Fixes
    • Enhanced data linking behavior to merge existing data intelligently instead of overwriting blindly, preventing unintended data loss.
    • Improved property preservation logic during data linking to maintain data integrity and consistency across records.

✏️ Tip: You can customize this high-level summary in your review settings.

@coderabbitai
Copy link
Contributor

coderabbitai bot commented Jan 15, 2026

📝 Walkthrough

Walkthrough

The change enhances the insert_link method in mdvproject.py to intelligently handle rows_as_columns links by merging subgroups from new data into existing links rather than overwriting them, while preserving properties through name_column comparison.

Changes

Cohort / File(s) Summary
Link insertion logic enhancement
python/mdvtools/mdvproject.py
Modified insert_link logic to merge subgroups into existing rows_as_columns links; compares name_column to preserve/replace properties; retains prior overwrite behavior for non-matching cases or missing links; metadata updated as before

Estimated code review effort

🎯 3 (Moderate) | ⏱️ ~20 minutes

Poem

🐰 Hop, hop, merging links with care,
Subgroups blend in columns fair,
Name by name, we match and mend,
Properties preserved, on properties depend!
No more blindly overwriting ways,
Smart merging brightens all our days!

🚥 Pre-merge checks | ✅ 3
✅ Passed checks (3 passed)
Check name Status Explanation
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title check ✅ Passed The title accurately summarizes the main change: merging subgroups when inserting rows_as_columns links, which directly addresses the bug fix described in the PR objectives.
Docstring Coverage ✅ Passed Docstring coverage is 100.00% which is sufficient. The required threshold is 80.00%.

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

✨ Finishing touches
  • 📝 Generate docstrings

🧹 Recent nitpick comments
python/mdvtools/mdvproject.py (1)

1284-1304: Redundant conditional branches and potential logic issue with subgroup merging.

Two concerns with the merge logic:

  1. Lines 1295-1300 are identical in both branches - the if-else produces the same result (llink[linktype] = data) regardless of whether name_column matches. The condition is effectively dead code.

  2. Subgroups are merged before the name_column check - If the intent is to overwrite (not merge) when name_column differs, the merge on lines 1291-1293 should happen after confirming name_column matches. Currently, even in the "overwrite" branch, data["subgroups"] already contains the merged result.

♻️ Suggested simplification
         # Check if link already exists and merge subgroups for rows_as_columns links
         if linktype == "rows_as_columns" and linktype in llink:
             existing_link = llink[linktype]
-            # Merge subgroups: preserve existing subgroups, add new ones from data
-            if "subgroups" in existing_link and "subgroups" in data:
-                # Merge subgroups dictionaries
-                merged_subgroups = existing_link["subgroups"].copy()
-                merged_subgroups.update(data["subgroups"])
-                data["subgroups"] = merged_subgroups
-            # Preserve other existing properties if they match
-            if existing_link.get("name_column") == data.get("name_column"):
-                # Same link configuration, merge subgroups
-                llink[linktype] = data
-            else:
-                # Different link configuration, overwrite (shouldn't happen in normal flow)
-                llink[linktype] = data
+            # Only merge subgroups if name_column matches (same link configuration)
+            if existing_link.get("name_column") == data.get("name_column"):
+                if "subgroups" in existing_link:
+                    # Preserve existing subgroups, add new ones from data
+                    merged_subgroups = existing_link["subgroups"].copy()
+                    merged_subgroups.update(data.get("subgroups", {}))
+                    data["subgroups"] = merged_subgroups
+            # Different name_column is not expected; fall through to overwrite
+            llink[linktype] = data
         else:
             # No existing link or not rows_as_columns type, overwrite as before
             llink[linktype] = data

This refactor:

  • Removes redundant branches
  • Only merges subgroups when name_column matches (matching the stated intent)
  • Uses data.get("subgroups", {}) to handle cases where data might not have the key

📜 Recent review details

Configuration used: Path: .coderabbit.yaml

Review profile: CHILL

Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between 076c4b2 and 9ecbe8d.

📒 Files selected for processing (1)
  • python/mdvtools/mdvproject.py
🧰 Additional context used
🧠 Learnings (2)
📓 Common learnings
Learnt from: xinaesthete
Repo: Taylor-CCB-Group/MDV PR: 0
File: :0-0
Timestamp: 2025-03-17T15:08:26.492Z
Learning: The PR titled "column link" introduces the concept of dynamic column links to allow charts to reactively update based on operations in linked data sources, replacing string-based column identifiers with more robust `FieldSpec` and `ColumnQuery` systems.
📚 Learning: 2025-03-17T15:08:26.492Z
Learnt from: xinaesthete
Repo: Taylor-CCB-Group/MDV PR: 0
File: :0-0
Timestamp: 2025-03-17T15:08:26.492Z
Learning: The PR titled "column link" introduces the concept of dynamic column links to allow charts to reactively update based on operations in linked data sources, replacing string-based column identifiers with more robust `FieldSpec` and `ColumnQuery` systems.

Applied to files:

  • python/mdvtools/mdvproject.py

✏️ Tip: You can disable this entire section by setting review_details to false in your review 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 and usage tips.

@xinaesthete
Copy link
Collaborator

I think I'd like to add a few tests to this, using some of the facilities we have for making mock-data projects.

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