Skip to content

cleanup: remove root-level layout_config and components from Dashboar…#1360

Merged
NaveenCode merged 7 commits into
mainfrom
cleanup/remove-dashboard-root-layout-fields
Jun 5, 2026
Merged

cleanup: remove root-level layout_config and components from Dashboar…#1360
NaveenCode merged 7 commits into
mainfrom
cleanup/remove-dashboard-root-layout-fields

Conversation

@NaveenCode

@NaveenCode NaveenCode commented May 19, 2026

Copy link
Copy Markdown
Contributor

Summary

  • Permanently removes deprecated root-level layout_config and components fields from the Dashboard system
  • All dashboard data now lives exclusively in dashboard.tabs[].layout_config and dashboard.tabs[].components
  • Adds cleanup_frozen_dashboard_root_fields management command to clean up existing ReportSnapshot JSON blobs

Migration steps (on deploy)

  1. Run data migration: python manage.py cleanup_frozen_dashboard_root_fields
  2. Run schema migration: python manage.py migrate ddpui 0161

Test plan

  • All 1592 backend tests pass (uv run pytest ddpui/tests/ --ignore=ddpui/tests/integration_tests)
  • Create a dashboard — verify no layout_config/components in API response
  • Open an existing report — verify it renders correctly
  • Duplicate a dashboard — verify tabs are copied correctly

Summary by CodeRabbit

  • New Features

    • Management utility to clean up legacy frozen dashboard data with dry-run support.
  • Refactor

    • Dashboard model and APIs migrated to a tabs-based structure.
    • Report snapshots now store tab-focused config and serialized filters (reduced redundant root fields).
    • Removed obsolete migration utilities.
  • Chores

    • Database migration applied to remove legacy dashboard columns.
  • Tests

    • Test suites updated to use the tabs-based dashboard shape.

…d (DALGO-1296)

- Drop layout_config and components columns from Dashboard model (migration 0161)
- Remove fields from DashboardResponse and FrozenDashboardConfig schemas
- Update report_service, dashboard_service, chart_service, and duplicate API to iterate tabs
- Add cleanup_frozen_dashboard_root_fields management command for ReportSnapshot JSON cleanup
- Delete obsolete migrate_dashboards_to_tabs and migrate_report_snapshots_to_tabs commands
- Update all test fixtures and assertions to use tabs structure
@NaveenCode NaveenCode self-assigned this May 19, 2026
@coderabbitai

coderabbitai Bot commented May 19, 2026

Copy link
Copy Markdown

Review Change Stack

Warning

Review limit reached

@NaveenCode, we couldn't start this review because you've reached your PR review rate limit.

More reviews will be available in 50 minutes and 43 seconds. Learn how PR review limits work.

Your organization has run out of usage credits. Purchase more in the billing tab.

⌛ How to resolve this issue?

After more reviews become available, a review can be triggered using the @coderabbitai review command as a PR comment. Alternatively, push new commits to this PR.

We recommend that you space out your commits to avoid hitting the rate limit.

🚦 How do rate limits work?

CodeRabbit enforces hourly rate limits for each developer per organization.

Our paid plans include higher PR review limits than trial, open-source, and free plans. In all cases, reviews become available again over time. During sustained high-volume PR review activity, CodeRabbit may temporarily slow when the next review becomes available.

Please see our Fair Usage Limits Policy for further information.

ℹ️ Review info
⚙️ Run configuration

Configuration used: Organization UI

Review profile: CHILL

Plan: Pro

Run ID: 114fc6aa-1051-4f7e-adcd-e3b27ada3103

📥 Commits

Reviewing files that changed from the base of the PR and between 103a97e and 82984ea.

📒 Files selected for processing (1)
  • ddpui/services/dashboard_service.py

Walkthrough

This PR removes root-level layout_config/components from models and schemas, drops the DB columns via migration, refactors services and APIs to operate on dashboard.tabs[*].components, updates report snapshot freezing/extraction and adds a cleanup command, and adjusts tests/fixtures to the tab-based structure.

Changes

Dashboard Tab-Based Structure Migration

Layer / File(s) Summary
Model and schema cleanup
ddpui/models/dashboard.py, ddpui/schemas/dashboard_schema.py, ddpui/schemas/report_schema.py
Dashboard model removes layout_config and components JSONField declarations; DashboardResponse and FrozenDashboardConfig schemas updated to remove those fields and define tab/filter-based structure; Dashboard.to_json() omits old keys.
Database schema migration
ddpui/migrations/0163_remove_dashboard_root_layout_components.py
Migration removes layout_config and components columns from dashboard table; documents that all data resides in tabs JSON array.
Report snapshot model reordering
ddpui/models/report.py
ReportSnapshot fields frozen_dashboard and frozen_chart_configs repositioned after period_end; surrounding explanatory comments removed; field types/defaults unchanged.
Snapshot freezing refactor
ddpui/core/reports/report_service.py
_freeze_dashboard removes root layout_config/components from payload, storing only tabs + filter_layout + serialized filters; _extract_chart_ids gathers chart IDs exclusively from tab-embedded components with deduplication.
Cleanup command for frozen snapshots
ddpui/management/commands/cleanup_frozen_dashboard_root_fields.py
New Django management command iterates ReportSnapshot.frozen_dashboard, identifies and removes stale root-level layout_config/components keys, bulk-updates snapshots with --dry-run support.
Dashboard duplication simplification
ddpui/api/dashboard_native_api.py
Removes copy module import and deep-copy/remapping of root layout_config/components; newly created dashboard relies on defaults; only remaps tabs via DashboardService.copy_tabs_with_filter_remapping.
Service layer refactor (charts, filters, validation)
ddpui/services/dashboard_service.py, ddpui/services/chart_service.py
DashboardService removes legacy in-function filter migration; apply_filters, get_dashboard_charts, and validate_dashboard_config traverse tabs[*].components; ChartService.get_chart_dashboards scans tabs for chart components.
Test fixtures and assertions — models, APIs, services
ddpui/tests/* (multiple test files)
All test fixtures updated to create dashboards with tabs structure; frozen snapshot assertions inspect tab-embedded components; added test for chart ID deduplication across multiple tabs.

🎯 3 (Moderate) | ⏱️ ~25 minutes

Possibly related PRs

Suggested reviewers

  • siddhant3030
  • himanshudube97
  • Ishankoradia
🚥 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 accurately describes the main objective: removing root-level layout_config and components from Dashboard. It reflects the primary structural change across the codebase and matches the PR's core intent.
Docstring Coverage ✅ Passed Docstring coverage is 91.89% which is sufficient. The required threshold is 80.00%.
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 cleanup/remove-dashboard-root-layout-fields

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.

@sentry

sentry Bot commented May 19, 2026

Copy link
Copy Markdown

Codecov Report

❌ Patch coverage is 14.89362% with 40 lines in your changes missing coverage. Please review.
✅ Project coverage is 59.58%. Comparing base (a358a4c) to head (82984ea).

Files with missing lines Patch % Lines
ddpui/services/dashboard_service.py 0.00% 40 Missing ⚠️
Additional details and impacted files
@@            Coverage Diff             @@
##             main    #1360      +/-   ##
==========================================
+ Coverage   59.52%   59.58%   +0.05%     
==========================================
  Files         138      138              
  Lines       16582    16544      -38     
==========================================
- Hits         9870     9857      -13     
+ Misses       6712     6687      -25     

☔ View full report in Codecov by Harness.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.

@coderabbitai coderabbitai Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Actionable comments posted: 2

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

Inline comments:
In `@ddpui/services/dashboard_service.py`:
- Around line 1053-1056: The component-validation loop is currently outside the
"for tab in dashboard.tabs or []" loop causing only the last tab's components to
be validated; move the loop that iterates over components (the "for
component_id, component_config in components.items():" block) inside the tab
loop so each tab's components are validated, ensure "components =
tab.get('components') or {}" is set per tab before that inner loop, and keep
using the same identifiers (components, component_id, component_config,
component_type) to preserve existing logic.

In `@ddpui/tests/models/test_dashboard_models.py`:
- Line 145: The fixture uses a non-production chart component shape ("chart-1":
{"type": "chart", "chart_id": 1}); update the component to match the tab
component contract by replacing the root chart_id with a config object using
config.chartId (e.g., under the "chart-1" component keep "type": "chart" and add
"config": {"chartId": 1}) so tests reflect the real production schema used by
services.
🪄 Autofix (Beta)

Fix all unresolved CodeRabbit comments on this PR:

  • Push a commit to this branch (recommended)
  • Create a new PR with the fixes

ℹ️ Review info
⚙️ Run configuration

Configuration used: Organization UI

Review profile: CHILL

Plan: Pro

Run ID: 3504812d-f6fe-47e2-9dff-76ce875ea57f

📥 Commits

Reviewing files that changed from the base of the PR and between 75cb6fd and a9b17c6.

📒 Files selected for processing (20)
  • ddpui/api/dashboard_native_api.py
  • ddpui/core/reports/report_service.py
  • ddpui/management/commands/cleanup_frozen_dashboard_root_fields.py
  • ddpui/management/commands/migrate_dashboards_to_tabs.py
  • ddpui/management/commands/migrate_report_snapshots_to_tabs.py
  • ddpui/migrations/0161_remove_dashboard_root_layout_components.py
  • ddpui/models/dashboard.py
  • ddpui/schemas/dashboard_schema.py
  • ddpui/schemas/report_schema.py
  • ddpui/services/chart_service.py
  • ddpui/services/dashboard_service.py
  • ddpui/tests/api_tests/test_charts_api.py
  • ddpui/tests/api_tests/test_dashboard_native_api.py
  • ddpui/tests/api_tests/test_public_report_api.py
  • ddpui/tests/api_tests/test_report_api.py
  • ddpui/tests/core/reports/test_report_service.py
  • ddpui/tests/models/test_dashboard_models.py
  • ddpui/tests/schema_tests/test_dashboard_schema.py
  • ddpui/tests/services/test_chart_service.py
  • ddpui/tests/services/test_dashboard_service.py
💤 Files with no reviewable changes (9)
  • ddpui/management/commands/migrate_report_snapshots_to_tabs.py
  • ddpui/models/dashboard.py
  • ddpui/schemas/report_schema.py
  • ddpui/management/commands/migrate_dashboards_to_tabs.py
  • ddpui/schemas/dashboard_schema.py
  • ddpui/api/dashboard_native_api.py
  • ddpui/tests/api_tests/test_dashboard_native_api.py
  • ddpui/tests/schema_tests/test_dashboard_schema.py
  • ddpui/tests/services/test_dashboard_service.py

Comment thread ddpui/services/dashboard_service.py Outdated
Comment thread ddpui/tests/models/test_dashboard_models.py Outdated
NaveenCode and others added 3 commits May 26, 2026 17:06

@coderabbitai coderabbitai Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

🧹 Nitpick comments (2)
ddpui/core/reports/report_service.py (1)

97-97: ⚡ Quick win

Rename unused loop variable to _comp_id.

The variable comp_id is not used in the loop body. Following Python convention, prefix unused variables with underscore.

♻️ Proposed fix
-        for tab in dashboard.tabs or []:
-            for comp_id, component in (tab.get("components") or {}).items():
+        for tab in dashboard.tabs or []:
+            for _comp_id, component in (tab.get("components") or {}).items():
                 comp_type = component.get("type")
🤖 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 `@ddpui/core/reports/report_service.py` at line 97, The loop in
report_service.py uses an unused loop variable comp_id in "for comp_id,
component in (tab.get('components') or {}).items()"; rename comp_id to _comp_id
to follow Python convention for unused variables and avoid linter warnings.
Update the loop header where this occurs (the for ... in ... .items() over
tab.get("components")) and ensure no other references to comp_id remain in the
loop body.
ddpui/schemas/report_schema.py (1)

78-79: 💤 Low value

Consider using Field(default_factory=list) for mutable defaults.

While Pydantic handles List[...] = [] safely, the explicit Field(default_factory=list) pattern is clearer and silences static analysis warnings.

♻️ Proposed refactor
-    metric_type_tag: Optional[str] = None
-    program_tags: List[str] = []
-    periods: List[Dict[str, Any]] = []
+    metric_type_tag: Optional[str] = None
+    program_tags: List[str] = Field(default_factory=list)
+    periods: List[Dict[str, Any]] = Field(default_factory=list)
🤖 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 `@ddpui/schemas/report_schema.py` around lines 78 - 79, Replace the mutable
default list assignments for program_tags and periods with Pydantic Field
default factories: import Field from pydantic and change the declarations of
program_tags: List[str] and periods: List[Dict[str, Any]] to use
Field(default_factory=list) so each model instance gets its own list; keep the
existing type annotations intact.
🤖 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 `@ddpui/core/reports/report_service.py`:
- Line 97: The loop in report_service.py uses an unused loop variable comp_id in
"for comp_id, component in (tab.get('components') or {}).items()"; rename
comp_id to _comp_id to follow Python convention for unused variables and avoid
linter warnings. Update the loop header where this occurs (the for ... in ...
.items() over tab.get("components")) and ensure no other references to comp_id
remain in the loop body.

In `@ddpui/schemas/report_schema.py`:
- Around line 78-79: Replace the mutable default list assignments for
program_tags and periods with Pydantic Field default factories: import Field
from pydantic and change the declarations of program_tags: List[str] and
periods: List[Dict[str, Any]] to use Field(default_factory=list) so each model
instance gets its own list; keep the existing type annotations intact.

ℹ️ Review info
⚙️ Run configuration

Configuration used: Organization UI

Review profile: CHILL

Plan: Pro

Run ID: 620b5080-2f13-43c9-8d6c-8eb8c3bc17d9

📥 Commits

Reviewing files that changed from the base of the PR and between ba13098 and 6f856d2.

📒 Files selected for processing (7)
  • ddpui/core/reports/report_service.py
  • ddpui/migrations/0163_remove_dashboard_root_layout_components.py
  • ddpui/models/dashboard.py
  • ddpui/models/report.py
  • ddpui/schemas/report_schema.py
  • ddpui/tests/core/reports/test_report_service.py
  • ddpui/tests/services/test_kpi_service.py
💤 Files with no reviewable changes (1)
  • ddpui/models/report.py
🚧 Files skipped from review as they are similar to previous changes (1)
  • ddpui/models/dashboard.py

@Ishankoradia Ishankoradia self-requested a review June 5, 2026 03:58
@NaveenCode NaveenCode merged commit a128879 into main Jun 5, 2026
4 of 5 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.

2 participants