Skip to content

Add content_type table to the dump data command#4042

Open
ahmedxgouda wants to merge 8 commits intoOWASP:mainfrom
ahmedxgouda:fix/dump-data
Open

Add content_type table to the dump data command#4042
ahmedxgouda wants to merge 8 commits intoOWASP:mainfrom
ahmedxgouda:fix/dump-data

Conversation

@ahmedxgouda
Copy link
Collaborator

@ahmedxgouda ahmedxgouda commented Feb 22, 2026

Proposed change

Resolves #4030

  • Added django_content_type table to the tables to dump in the dump_data command.
  • Updated makefile targets, docker compose, and CI/CD to include truncating the content_type table data before loading (necessary).

Checklist

  • Required: I followed the contributing workflow
  • Required: I verified that my code works as intended and resolves the issue as described
  • Required: I ran make check-test locally: all warnings addressed, tests passed
  • I used AI for code, documentation, tests, or communication related to this PR

@coderabbitai
Copy link
Contributor

coderabbitai bot commented Feb 22, 2026

Note

Reviews paused

It looks like this branch is under active development. To avoid overwhelming you with review comments due to an influx of new commits, CodeRabbit has automatically paused this review. You can configure this behavior by changing the reviews.auto_review.auto_pause_after_reviewed_commits setting.

Use the following commands to manage reviews:

  • @coderabbitai resume to resume automatic reviews.
  • @coderabbitai review to trigger a single review.

Use the checkboxes below for quick actions:

  • ▶️ Resume reviews
  • 🔍 Trigger review

Walkthrough

Truncates django_content_type (CASCADE) before restoring Postgres dumps, adds public.django_content_type to dump defaults, and updates CI workflows, Makefile targets, Docker Compose data-loader commands, a management command, and its test.

Changes

Cohort / File(s) Summary
CI workflows
.github/workflows/run-ci-cd.yaml, .github/workflows/run-fuzz-tests.yaml
Inserted explicit psql TRUNCATE of public.django_content_type CASCADE and echo diagnostics immediately before pg_restore in Postgres data-load steps; removed conditional failure path to run truncate-then-load unconditionally.
Makefile targets
backend/Makefile
Added container-selection macros (GET_DB_CONTAINER, GET_BACKEND_CONTAINER), generic exec targets (exec-backend-command-%, exec-db-command-%), reworked exec routing to delegate to dev targets, added load-data-% parameterized target that truncates content types and runs pg_restore, and removed several env-specific exec targets.
Django management command
backend/apps/common/management/commands/dump_data.py
Added public.django_content_type to the default table list included in dumps.
Backend tests
backend/tests/apps/common/management/commands/dump_data_test.py
Updated test expectation to include public.django_content_type in the constructed pg_dump table filters.
Docker Compose data loaders
docker-compose/e2e/compose.yaml, docker-compose/fuzz/compose.yaml
Prepended a psql TRUNCATE django_content_type CASCADE command to the data-loader service command sequence before invoking pg_restore.

Estimated code review effort

🎯 3 (Moderate) | ⏱️ ~20 minutes

Possibly related PRs

Suggested labels

docker

Suggested reviewers

  • kasya
  • arkid15r
🚥 Pre-merge checks | ✅ 4 | ❌ 1

❌ Failed checks (1 warning)

Check name Status Explanation Resolution
Docstring Coverage ⚠️ Warning Docstring coverage is 0.00% which is insufficient. The required threshold is 80.00%. Write docstrings for the functions missing them to satisfy the coverage threshold.
✅ Passed checks (4 passed)
Check name Status Explanation
Title check ✅ Passed The title accurately and concisely summarizes the primary change: adding the django_content_type table to the dump_data command.
Linked Issues check ✅ Passed The PR fully addresses issue #4030 by adding django_content_type table to dump_data command and updating related infrastructure for proper data loading.
Out of Scope Changes check ✅ Passed All changes are directly scoped to resolving issue #4030: adding content_type table to dumps and updating infrastructure to handle truncation before load operations.
Description check ✅ Passed The PR description clearly describes the changeset: adding django_content_type to the dump_data command and updating related infrastructure (Makefile, Docker Compose, CI/CD) to truncate this table before loading.

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

✨ Finishing Touches
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Post copyable unit tests in a comment
📝 Coding Plan
  • Generate coding plan for human review comments

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.

Tip

You can customize the tone of the review comments and chat replies.

Configure the tone_instructions setting to customize the tone of the review comments and chat replies. For example, you can set the tone to Act like a strict teacher, Act like a pirate and more.

cubic-dev-ai[bot]
cubic-dev-ai bot previously approved these changes Feb 22, 2026
Copy link
Contributor

@cubic-dev-ai cubic-dev-ai bot left a comment

Choose a reason for hiding this comment

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

No issues found across 7 files

Confidence score: 5/5

  • Automated review surfaced no issues in the provided summaries.
  • No files require special attention.

Copy link
Contributor

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

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

Actionable comments posted: 1

Caution

Some comments are outside the diff and can’t be posted inline due to platform limitations.

⚠️ Outside diff range comments (1)
backend/tests/apps/common/management/commands/dump_data_test.py (1)

183-216: ⚠️ Potential issue | 🟡 Minor

test_dump_data_with_custom_tables doesn't assert public.django_content_type is present.

When --table public.custom_table is passed, argparse appends to the default list, so --table=public.django_content_type will be in cmd_args. The test should assert this to catch any future regression where the default entry is accidentally dropped.

✅ Suggested assertion
 assert "--table=public.owasp_*" in cmd_args
 assert "--table=public.github_*" in cmd_args
 assert "--table=public.custom_table" in cmd_args
+assert "--table=public.django_content_type" in cmd_args
🤖 Prompt for AI Agents
Verify each finding against the current code and only fix it if needed.

In `@backend/tests/apps/common/management/commands/dump_data_test.py` around lines
183 - 216, The test test_dump_data_with_custom_tables fails to assert that the
default table entry was preserved; update the test to also assert that
"--table=public.django_content_type" is present in cmd_args after call_command.
Locate the assertions near the end of test_dump_data_with_custom_tables (they
reference run_call, cmd_args and mock_run.call_args_list) and add a line
asserting "--table=public.django_content_type" in cmd_args to ensure the default
list isn't dropped when passing "--table public.custom_table".
🤖 Prompt for all review comments with AI agents
Verify each finding against the current code and only fix it if needed.

Inline comments:
In `@backend/Makefile`:
- Around line 123-127: The load-data-staging Makefile target is calling
exec-db-command-fuzz (which connects to fuzz-nest-db) causing a
credential/container mismatch; add a new Makefile target named
exec-db-command-staging (modeled after exec-db-command and exec-db-command-fuzz)
that runs commands against the staging container (staging-nest-db) using the
staging docker-compose file (docker-compose/staging/compose.yaml), then change
load-data-staging to invoke exec-db-command-staging instead of
exec-db-command-fuzz and keep the CMD environment/psql/pg_restore arguments
as-is for nest_user_staging/nest_db_staging.

---

Outside diff comments:
In `@backend/tests/apps/common/management/commands/dump_data_test.py`:
- Around line 183-216: The test test_dump_data_with_custom_tables fails to
assert that the default table entry was preserved; update the test to also
assert that "--table=public.django_content_type" is present in cmd_args after
call_command. Locate the assertions near the end of
test_dump_data_with_custom_tables (they reference run_call, cmd_args and
mock_run.call_args_list) and add a line asserting
"--table=public.django_content_type" in cmd_args to ensure the default list
isn't dropped when passing "--table public.custom_table".

@codecov
Copy link

codecov bot commented Feb 22, 2026

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 99.39%. Comparing base (40eb7d3) to head (1aa29c5).

Additional details and impacted files

Impacted file tree graph

@@           Coverage Diff           @@
##             main    #4042   +/-   ##
=======================================
  Coverage   99.39%   99.39%           
=======================================
  Files         520      520           
  Lines       16442    16445    +3     
  Branches     2241     2241           
=======================================
+ Hits        16343    16346    +3     
  Misses         62       62           
  Partials       37       37           
Flag Coverage Δ
backend 99.83% <100.00%> (+<0.01%) ⬆️
frontend 98.17% <ø> (ø)

Flags with carried forward coverage won't be shown. Click here to find out more.

Files with missing lines Coverage Δ
...ckend/apps/common/management/commands/dump_data.py 100.00% <ø> (ø)
...kend/apps/common/management/commands/purge_data.py 100.00% <100.00%> (ø)

Continue to review full report in Codecov by Sentry.

Legend - Click here to learn more
Δ = absolute <relative> (impact), ø = not affected, ? = missing data
Powered by Codecov. Last update 40eb7d3...1aa29c5. Read the comment docs.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.
  • 📦 JS Bundle Analysis: Save yourself from yourself by tracking and limiting bundle sizes in JS merges.

coderabbitai[bot]
coderabbitai bot previously approved these changes Feb 22, 2026
@ahmedxgouda ahmedxgouda marked this pull request as ready for review February 22, 2026 20:51
Copy link
Collaborator

@arkid15r arkid15r left a comment

Choose a reason for hiding this comment

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

Could you look into making this code DRYer?

Copy link
Contributor

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

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

Actionable comments posted: 1

🤖 Prompt for all review comments with AI agents
Verify each finding against the current code and only fix it if needed.

Inline comments:
In `@backend/Makefile`:
- Around line 62-67: The current exec-backend-command-it target delegates to
exec-backend-command-dev which drops interactive TTY (-it) behavior; update the
else branch to delegate to the interactive dev target
(exec-backend-command-dev-it) or otherwise invoke the interactive variant so CMD
runs with TTY preserved (i.e., replace @$(MAKE) exec-backend-command-dev
CMD="$(CMD)" 2>/dev/null with a call to the interactive dev target that
preserves -it behavior).

ℹ️ Review info

Configuration used: Path: .coderabbit.yaml

Review profile: CHILL

Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between 2998831 and 957f199.

📒 Files selected for processing (2)
  • .github/workflows/run-ci-cd.yaml
  • backend/Makefile
🚧 Files skipped from review as they are similar to previous changes (1)
  • .github/workflows/run-ci-cd.yaml

coderabbitai[bot]
coderabbitai bot previously approved these changes Feb 25, 2026
@ahmedxgouda ahmedxgouda requested a review from arkid15r February 25, 2026 13:15
Copy link
Collaborator

@arkid15r arkid15r left a comment

Choose a reason for hiding this comment

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

Please revert unrelated changes.

Comment on lines +340 to +341
echo "Truncating content_type table" &&
psql -h localhost -U nest_user_e2e -d nest_db_e2e -c "TRUNCATE django_content_type CASCADE;" &&
Copy link
Collaborator

Choose a reason for hiding this comment

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

Could you look into making this code DRYer?

I meant repetitive TRUNCATE django_content_type CASCADE by that.

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

I thought combining the repeated make commands to one command is a good idea. Commands like load-data have an identical behavior, the only difference is the environment.

Copy link
Collaborator

Choose a reason for hiding this comment

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

It's difficult to read/understand. Even if we do it -- it should be done in a different PR.

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

I reverted the changes. I think I can make it more readable in another PR. I will implement a common makefile target and pass environment variables for each specific target:

_load-data-common:
	@echo "Truncating content_type table"
	@CMD="psql -U $(DB_USER) -d $(DB_NAME) -c \"TRUNCATE django_content_type CASCADE;\"" $(MAKE) $(EXEC_DB_TARGET)
	@echo "Loading Nest $(DB_ENV) data"
	@CMD="pg_restore -U $(DB_USER) -d $(DB_NAME)  < ./backend/data/nest..dump" $(MAKE) $(EXEC_DB_TARGET)

Copy link
Collaborator

Choose a reason for hiding this comment

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

Maybe it'd be better extend the purge data script and run it before the data loading one?

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

Sounds a good idea, but this should be in another PR right? If you don't have any comments, you may merge it and I will work on that in the next PR.

Copy link
Collaborator

Choose a reason for hiding this comment

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

No, that was a suggestion on how to avoid the truncate command related code duplication.

Copy link
Collaborator

@arkid15r arkid15r left a comment

Choose a reason for hiding this comment

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

It's also seems it won't work for staging recently migrated to ECS.

Comment on lines +340 to +341
echo "Truncating content_type table" &&
psql -h localhost -U nest_user_e2e -d nest_db_e2e -c "TRUNCATE django_content_type CASCADE;" &&
Copy link
Collaborator

Choose a reason for hiding this comment

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

It's difficult to read/understand. Even if we do it -- it should be done in a different PR.

@sonarqubecloud
Copy link

Copy link
Contributor

@cubic-dev-ai cubic-dev-ai bot left a comment

Choose a reason for hiding this comment

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

1 issue found across 3 files (changes from recent commits).

Prompt for AI agents (unresolved issues)

Check if these issues are valid — if so, understand the root cause of each and fix them. If appropriate, use sub-agents to investigate and fix each issue separately.


<file name="backend/apps/common/management/commands/purge_data.py">

<violation number="1" location="backend/apps/common/management/commands/purge_data.py:35">
P1: Truncating `django_content_type` with `CASCADE` wipes global Django permissions that this dump flow does not restore.</violation>
</file>

Reply with feedback, questions, or to request a fix. Tag @cubic-dev-ai to re-run a review.

@ahmedxgouda ahmedxgouda requested a review from arkid15r March 16, 2026 13:50
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Update dump_data command

2 participants