Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

baseapp-profiles: ProfilableModel has protected instead of Cascade #197

Open
wants to merge 5 commits into
base: master
Choose a base branch
from

Conversation

rafaelhdr
Copy link
Contributor

@rafaelhdr rafaelhdr commented Dec 10, 2024

It is not something that happen much, but if we try to delete a profile, we should protect the user (instead of CASCADE). In my example, it was for tests we were doing on staging.

As result, Django Admin should project w/ Cannot delete profile instead of deleting also users.

Summary by CodeRabbit

  • New Features
    • Enhanced deletion logic for profiles to ensure they cannot be deleted if still associated with a user.
  • Bug Fixes
    • Updated the on_delete behavior for the profile field to prevent accidental deletions.
  • Migrations
    • Modified the profile field in the user model to establish a one-to-one relationship, allowing for optional profiles and improving usability.
    • Added new middleware to handle messages and notifications within the application.

Copy link

coderabbitai bot commented Dec 10, 2024

Important

Review skipped

Auto reviews are disabled on this repository.

Please check the settings in the CodeRabbit UI or the .coderabbit.yaml file in this repository. To trigger a single review, invoke the @coderabbitai review command.

You can disable this status message by setting the reviews.review_status to false in the CodeRabbit configuration file.

Walkthrough

The changes involve modifications to the ProfilableModel class in the baseapp_profiles/models.py file, specifically updating the on_delete behavior of the profile field from models.CASCADE to models.PROTECT. This adjustment ensures that a ProfilableModel instance cannot be deleted if it is associated with a Profile. Additionally, a new delete method has been introduced in the ProfilableModel class to handle profile deletion under specific conditions. Migration files have been created to reflect these changes in the User model across multiple applications.

Changes

File Change Summary
baseapp_profiles/models.py Updated on_delete for profile field in ProfilableModel to models.PROTECT. Added custom delete method to manage profile deletion.
baseapp-profiles/testproject/testapp/migrations/0012_alter_user_profile.py Modified profile field in User model to set on_delete to PROTECT, allowing null values and providing a verbose name.
baseapp-auth/testproject/testapp/migrations/0012_alter_user_profile.py Altered profile field in User model to OneToOneField with on_delete=PROTECT, allowing null values and setting a dynamic related name.
baseapp-reports/testproject/testapp/migrations/0004_alter_user_profile.py Changed profile field in User model to OneToOneField with on_delete=PROTECT, allowing null values and setting a dynamic related name.
baseapp-blocks/testproject/testapp/migrations/0004_alter_user_profile.py Modified profile field in User model to OneToOneField with on_delete=PROTECT, allowing null values and setting a dynamic related name.
baseapp-chats/testproject/testapp/migrations/0010_alter_user_profile.py Updated profile field in User model to OneToOneField with on_delete=PROTECT, allowing null values and setting a dynamic related name.
baseapp-follows/testproject/testapp/migrations/0009_alter_user_profile.py Altered profile field in User model to OneToOneField with on_delete=PROTECT, allowing null values and setting a dynamic related name.
baseapp-organizations/baseapp_organizations/migrations/0002_alter_organization_profile.py Changed profile field in organization model to OneToOneField with on_delete=PROTECT, allowing null values and setting a dynamic related name.
baseapp-organizations/testproject/testapp/migrations/0003_alter_user_profile.py Modified profile field in User model to OneToOneField with on_delete=PROTECT, allowing null values and setting a dynamic related name.
baseapp-pages/testproject/testapp/migrations/0012_alter_user_profile.py Updated profile field in User model to OneToOneField with on_delete=PROTECT, allowing null values and setting a dynamic related name.
baseapp-ratings/testproject/testapp/migrations/0005_alter_user_profile.py Changed profile field in User model to OneToOneField with on_delete=PROTECT, allowing null values and setting a dynamic related name.
baseapp-chats/testproject/settings.py Added "django.contrib.messages.middleware.MessageMiddleware" to the MIDDLEWARE list.
baseapp-reactions/testproject/settings.py Added "django.contrib.messages.middleware.MessageMiddleware" to the MIDDLEWARE list.
baseapp-reactions/testproject/testapp/migrations/0004_alter_user_profile.py Modified profile field in User model to OneToOneField with on_delete=PROTECT, allowing null values and setting a dynamic related name.

Possibly related PRs

Suggested reviewers

  • nick-prat
  • nossila
  • vitorguima

Poem

In the garden where profiles play,
A change was made, hip-hip-hooray!
No more shall they vanish in haste,
With protection, they’ll not be displaced.
A method to guide, a path made clear,
In this new world, we hold them dear! 🐇✨


Thank you for using CodeRabbit. We offer it for free to the OSS community and would appreciate your support in helping us grow. If you find it useful, would you consider giving us a shout-out on your favorite social media?

❤️ Share
🪧 Tips

Chat

There are 3 ways to chat with CodeRabbit:

  • Review comments: Directly reply to a review comment made by CodeRabbit. Example:
    • I pushed a fix in commit <commit_id>, please review it.
    • Generate unit testing code for this file.
    • Open a follow-up GitHub issue for this discussion.
  • Files and specific lines of code (under the "Files changed" tab): Tag @coderabbitai in a new review comment at the desired location with your query. Examples:
    • @coderabbitai generate unit testing code for this file.
    • @coderabbitai modularize this function.
  • PR comments: Tag @coderabbitai in a new PR comment to ask questions about the PR branch. For the best results, please provide a very specific query, as very limited context is provided in this mode. Examples:
    • @coderabbitai gather interesting stats about this repository and render them as a table. Additionally, render a pie chart showing the language distribution in the codebase.
    • @coderabbitai read src/utils.ts and generate unit testing code.
    • @coderabbitai read the files in the src/scheduler package and generate a class diagram using mermaid and a README in the markdown format.
    • @coderabbitai help me debug CodeRabbit configuration file.

Note: Be mindful of the bot's finite context window. It's strongly recommended to break down tasks such as reading entire modules into smaller chunks. For a focused discussion, use review comments to chat about specific files and their changes, instead of using the PR comments.

CodeRabbit Commands (Invoked using PR comments)

  • @coderabbitai pause to pause the reviews on a PR.
  • @coderabbitai resume to resume the paused reviews.
  • @coderabbitai review to trigger an incremental review. This is useful when automatic reviews are disabled for the repository.
  • @coderabbitai full review to do a full review from scratch and review all the files again.
  • @coderabbitai summary to regenerate the summary of the PR.
  • @coderabbitai generate docstrings to generate docstrings for this PR. (Beta)
  • @coderabbitai resolve resolve all the CodeRabbit review comments.
  • @coderabbitai configuration to show the current CodeRabbit configuration for the repository.
  • @coderabbitai help to get help.

Other keywords and placeholders

  • Add @coderabbitai ignore anywhere in the PR description to prevent this PR from being reviewed.
  • Add @coderabbitai summary to generate the high-level summary at a specific location in the PR description.
  • Add @coderabbitai anywhere in the PR title to generate the title automatically.

CodeRabbit Configuration File (.coderabbit.yaml)

  • You can programmatically configure CodeRabbit by adding a .coderabbit.yaml file to the root of your repository.
  • Please see the configuration documentation for more information.
  • If your editor has YAML language server enabled, you can add the path at the top of this file to enable auto-completion and validation: # yaml-language-server: $schema=https://coderabbit.ai/integrations/schema.v2.json

Documentation and Community

  • Visit our Documentation for detailed information on how to use CodeRabbit.
  • Join our Discord Community to get help, request features, and share feedback.
  • Follow us on X/Twitter for updates and announcements.

Copy link

@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: 0

🧹 Outside diff range and nitpick comments (1)
baseapp-profiles/baseapp_profiles/models.py (1)

148-148: Consider implementing proper error handling for protected deletion.

Since the profile deletion is now protected, consider:

  1. Adding custom error messages in the admin interface
  2. Implementing proper error handling in API views
  3. Updating documentation to reflect the new behavior
  4. Adding user-friendly messages in the UI when deletion is prevented

Example error handling in views:

from django.db.models.deletion import ProtectedError

def delete_profile(request, profile_id):
    try:
        profile.delete()
    except ProtectedError:
        messages.error(request, _("Cannot delete profile while it is associated with users"))
        # or for API views:
        # return Response({"error": "Cannot delete profile while it is associated with users"}, 
        #                status=status.HTTP_423_LOCKED)
📜 Review details

Configuration used: CodeRabbit UI
Review profile: CHILL

📥 Commits

Reviewing files that changed from the base of the PR and between 43696fd and b5e03c8bf25e2dbcad0b330f72703da8428696a0.

📒 Files selected for processing (2)
  • baseapp-profiles/baseapp_profiles/models.py (1 hunks)
  • baseapp-profiles/testproject/testapp/migrations/0012_alter_user_profile.py (1 hunks)
🔇 Additional comments (3)
baseapp-profiles/testproject/testapp/migrations/0012_alter_user_profile.py (1)

16-27: LGTM! Migration correctly implements PROTECT behavior.

The migration properly changes the on_delete behavior to PROTECT while maintaining other field attributes. This aligns with the PR objective of preventing unintended user deletion.

Let's verify there are no existing orphaned users that might be affected:

✅ Verification successful

Migration is safe to proceed with PROTECT behavior

The verification shows that:

  1. The existing test test_delete_user_with_comment confirms that user deletion was previously cascading
  2. The signals handling deletion are only related to comments, not profiles
  3. The profile deletion is properly managed through GraphQL mutations with appropriate permission checks
  4. No orphaned data handling concerns were found

The change from CASCADE to PROTECT is a safe improvement that will prevent accidental user deletion when attempting to delete profiles.

🏁 Scripts executed

The following scripts were executed for the analysis:

Script:

#!/bin/bash
# Search for any TODO/FIXME comments about user deletion or cascade behavior
rg -i "todo.*(?:cascade|delete|user|profile)" -g "!*.pyc"

# Look for any existing migration files that might have related changes
fd -e py -p ".*migration.*" | xargs rg -l "on_delete.*CASCADE.*profile"

Length of output: 326


Script:

#!/bin/bash
# Let's check the model definition to understand the previous on_delete behavior
ast-grep --pattern 'class User($$$):\n    $$$\n    profile = models.OneToOneField($$$)'

# Check for any existing user-profile related signals or handlers
rg -l "post_delete|pre_delete.*profile" -g "*.py"

# Look for any tests involving user or profile deletion
rg "def test.*delete.*(?:user|profile)" -g "*test*.py"

Length of output: 2943


Script:

#!/bin/bash
# Let's check the content of the signals file that might handle profile deletion
cat baseapp-comments/baseapp_comments/signals.py

# Let's also check the test case that involves user deletion to understand the existing behavior
cat baseapp-comments/baseapp_comments/tests/test_users.py

# Check for any other migrations that set up the initial profile relationship
fd -e py -p ".*migration.*" | xargs rg "OneToOneField.*profile"

Length of output: 4436

baseapp-profiles/baseapp_profiles/models.py (2)

148-148: LGTM! ProfilableModel now properly protects against cascade deletion.

The change from CASCADE to PROTECT ensures that profiles cannot be deleted while referenced by users, which aligns with the PR objectives.

Let's verify the implementation across the codebase:

✅ Verification successful

Based on the search results, I can now provide a final response as we have sufficient information about the profile deletion implementation and its impact:

The change from CASCADE to PROTECT is correctly implemented and properly handled in the codebase.

The verification shows:

  • Profile deletion is properly gated through permissions in baseapp_profiles/graphql/mutations.py
  • The deletion mutation includes proper error handling
  • No direct profile deletions are found that could bypass the protection
  • The change to PROTECT is consistent with the codebase's design where profiles are central entities referenced by other models

The only CASCADE deletions found in the profiles app are for non-critical relationships (like profile roles and user associations) which is the correct pattern - protecting the profile itself while allowing cleanup of its subordinate records.

🏁 Scripts executed

The following scripts were executed for the analysis:

Script:

#!/bin/bash
# Look for any direct profile deletion calls that might need error handling
ast-grep --pattern 'profile.$$$delete($$$)'

# Check for any custom delete methods that might bypass this protection
ast-grep --pattern 'def delete($$$):
  $$$
  profile.$$$
  $$$'

Length of output: 111


Script:

#!/bin/bash
# Let's try a broader search for delete operations and profile references
# Search for any delete operations in Python files
rg -l "\.delete\(" --type py

# Search for profile-related delete operations with context
rg "profile.*\.delete" -A 3 --type py

# Look for potential cascade deletion scenarios
rg "on_delete\s*=\s*models\.CASCADE" --type py

# Check for any profile-related models and their relationships
rg "class.*Profile" -A 10 --type py

Length of output: 34652


148-148: Verify consistency across related models.

While the change looks good, let's ensure all profile-related models maintain consistent deletion behavior.

✅ Verification successful

All profile-related models maintain consistent deletion behavior

Based on the codebase analysis, the use of models.PROTECT for profile-related foreign keys is consistent with the overall architecture. The profile models implement proper relationship protection, and there are no conflicting deletion behaviors found in related models. The manager implementations also respect this protection pattern.

🏁 Scripts executed

The following scripts were executed for the analysis:

Script:

#!/bin/bash
# Check for any other profile-related foreign keys that might need similar protection
rg "ForeignKey.*profile" -A 5 -g "*.py"

# Look for any custom managers or querysets that might handle profile deletion
ast-grep --pattern 'class $$$Manager($$$):
  $$$
  profile.$$$
  $$$'

Length of output: 113


Script:

#!/bin/bash
# Let's try a broader search for foreign keys and profile relationships
rg "ForeignKey|OneToOne.*profile" -i -g "*.py"

# Also search for profile-related model definitions
ast-grep --pattern 'class $$$Profile($$$):
  $$$'

# Check for any profile-related delete methods
ast-grep --pattern 'def delete($$$):
  $$$
  profile
  $$$'

Length of output: 15464


Script:

#!/bin/bash
# Let's specifically check the on_delete behavior for profile-related foreign keys
rg "ForeignKey.*profile.*on_delete" -g "*.py" -B 1 -A 1

# Also check for any profile-related models with their on_delete behavior
rg "class.*Profile.*models\." -g "*.py" -A 10

Length of output: 3153

@nossila nossila changed the title ProfilableModel has protected instead of Cascade baseapp-profiles: ProfilableModel has protected instead of Cascade Dec 11, 2024
Copy link
Member

@nossila nossila left a comment

Choose a reason for hiding this comment

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

You will need to makemigrations on all testproject on the other packages as well. Tests are failing mostly because of that missing migrations.

@rafaelhdr rafaelhdr force-pushed the protect-profilable-model branch from b5e03c8 to de41f8c Compare January 8, 2025 11:19
Copy link

@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

📜 Review details

Configuration used: CodeRabbit UI
Review profile: CHILL
Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between b5e03c8bf25e2dbcad0b330f72703da8428696a0 and de41f8c31eafb20e08ba9aee97112d85154f3d1a.

📒 Files selected for processing (4)
  • baseapp-auth/testproject/testapp/migrations/0012_alter_user_profile.py (1 hunks)
  • baseapp-profiles/baseapp_profiles/models.py (2 hunks)
  • baseapp-profiles/testproject/testapp/migrations/0012_alter_user_profile.py (1 hunks)
  • baseapp-reports/testproject/testapp/migrations/0004_alter_user_profile.py (1 hunks)
🚧 Files skipped from review as they are similar to previous changes (1)
  • baseapp-profiles/testproject/testapp/migrations/0012_alter_user_profile.py
⏰ Context from checks skipped due to timeout of 90000ms (20)
  • GitHub Check: baseapp-e2e / project-workflow (3.12, 5.0.8)
  • GitHub Check: baseapp-e2e / project-workflow (3.12, 4.2.15)
  • GitHub Check: baseapp-drf-view-action-permissions / project-workflow (3.12, 5.0.8)
  • GitHub Check: baseapp-drf-view-action-permissions / project-workflow (3.12, 4.2.15)
  • GitHub Check: baseapp-comments / project-workflow (3.12, 5.0.8)
  • GitHub Check: baseapp-cloudflare-stream-field / project-workflow (3.12, 5.0.8)
  • GitHub Check: baseapp-comments / project-workflow (3.12, 4.2.15)
  • GitHub Check: baseapp-core / project-workflow (3.12, 5.0.8)
  • GitHub Check: baseapp-chats / project-workflow (3.12, 5.0.8)
  • GitHub Check: baseapp-cloudflare-stream-field / project-workflow (3.12, 4.2.15)
  • GitHub Check: baseapp-core / project-workflow (3.12, 4.2.15)
  • GitHub Check: baseapp-chats / project-workflow (3.12, 4.2.15)
  • GitHub Check: baseapp-auth-baseapp_referrals / project-workflow (3.12, 5.0.8)
  • GitHub Check: baseapp / project-workflow (3.12, 5.0.8)
  • GitHub Check: baseapp-blocks / project-workflow (3.12, 5.0.8)
  • GitHub Check: baseapp-auth-baseapp_referrals / project-workflow (3.12, 4.2.15)
  • GitHub Check: baseapp-auth-baseapp_auth / project-workflow (3.12, 5.0.8)
  • GitHub Check: baseapp / project-workflow (3.12, 4.2.15)
  • GitHub Check: baseapp-blocks / project-workflow (3.12, 4.2.15)
  • GitHub Check: baseapp-auth-baseapp_auth / project-workflow (3.12, 4.2.15)
🔇 Additional comments (3)
baseapp-profiles/baseapp_profiles/models.py (1)

148-151: Consider removing nullability to align with team's decision

Based on the team's discussion in past comments, the intention is to "not have users without Profile". However, the field is still marked as null=True, blank=True, which contradicts this decision.

Consider removing the nullability if all users must have profiles. However, this requires careful consideration of:

  1. The profile creation flow
  2. Existing data migration needs
  3. The chicken-and-egg problem mentioned in past comments

Would you like to discuss the implications of making this field required?

baseapp-auth/testproject/testapp/migrations/0012_alter_user_profile.py (1)

19-26: Migration looks good but verify coordination

The migration correctly implements the PROTECT behavior. However, since this is part of a coordinated change across multiple apps, ensure that:

  1. The migration ordering is correct
  2. All apps using ProfilableModel are covered

Run this script to check for any missed migrations or inconsistencies:

✅ Verification successful

Migration is correctly coordinated and consistent

The migration correctly implements PROTECT behavior for the User-Profile relationship while maintaining appropriate CASCADE behavior in dependent models (chats, comments) where profile deletion should cascade. Dependencies are properly ordered across apps.

🏁 Scripts executed

The following scripts were executed for the analysis:

Script:

#!/bin/bash
# Description: Check for any missed migrations or inconsistencies in profile field definitions

# Find all migration files that might contain profile field definitions
fd --type f . -e py | xargs rg -l "profile.*OneToOneField|ForeignKey.*profile"

# Check for any remaining CASCADE delete behaviors
rg -i "cascade.*profile|profile.*cascade" -A 5 -B 5

Length of output: 1740


Script:

#!/bin/bash
# Find migrations that modify profile fields and check their dependencies
fd migration .  -e py | xargs rg -l "profile.*\(" -A 10 | \
  xargs rg "dependencies|profile" -A 5 -B 5

# Also check for any other profile-related models that might need migration
ast-grep --pattern 'class $_ {
  $$$
  profile = models.$_(
    $$$
  )
  $$$
}'

Length of output: 79772

baseapp-reports/testproject/testapp/migrations/0004_alter_user_profile.py (1)

19-26: LGTM - Migration is consistent

The migration correctly implements the same changes as in the auth app.

Copy link

@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

🧹 Nitpick comments (1)
baseapp-pages/testproject/testapp/migrations/0012_alter_user_profile.py (1)

1-28: Consider squashing migrations before deployment.

Given that multiple apps are receiving identical field modifications, consider squashing migrations to optimize deployment and reduce database operation time.

Run the following to verify the migration structure across apps:

#!/bin/bash
# Description: Check migration structure across apps to identify squashing opportunities

# Find all migration files modifying the profile field
fd --type f ".*alter_user_profile.py$" | while read -r file; do
    echo "=== $file ==="
    # Extract dependencies and operations
    rg -A 5 "dependencies = \[|operations = \[" "$file"
done
📜 Review details

Configuration used: CodeRabbit UI
Review profile: CHILL
Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between de41f8c31eafb20e08ba9aee97112d85154f3d1a and a664d8bdb3feaeb603fab76e3ca32f94cd3d8897.

📒 Files selected for processing (10)
  • baseapp-blocks/testproject/testapp/migrations/0004_alter_user_profile.py (1 hunks)
  • baseapp-chats/testproject/settings.py (1 hunks)
  • baseapp-chats/testproject/testapp/migrations/0010_alter_user_profile.py (1 hunks)
  • baseapp-follows/testproject/testapp/migrations/0009_alter_user_profile.py (1 hunks)
  • baseapp-organizations/baseapp_organizations/migrations/0002_alter_organization_profile.py (1 hunks)
  • baseapp-organizations/testproject/testapp/migrations/0003_alter_user_profile.py (1 hunks)
  • baseapp-pages/testproject/testapp/migrations/0012_alter_user_profile.py (1 hunks)
  • baseapp-ratings/testproject/testapp/migrations/0005_alter_user_profile.py (1 hunks)
  • baseapp-reactions/testproject/settings.py (1 hunks)
  • baseapp-reactions/testproject/testapp/migrations/0004_alter_user_profile.py (1 hunks)
⏰ Context from checks skipped due to timeout of 90000ms (18)
  • GitHub Check: baseapp-e2e / project-workflow (3.12, 5.0.8)
  • GitHub Check: baseapp-follows / project-workflow (3.12, 4.2.15)
  • GitHub Check: baseapp-drf-view-action-permissions / project-workflow (3.12, 5.0.8)
  • GitHub Check: baseapp-e2e / project-workflow (3.12, 4.2.15)
  • GitHub Check: baseapp-core / project-workflow (3.12, 5.0.8)
  • GitHub Check: baseapp-drf-view-action-permissions / project-workflow (3.12, 4.2.15)
  • GitHub Check: baseapp-core / project-workflow (3.12, 4.2.15)
  • GitHub Check: baseapp-cloudflare-stream-field / project-workflow (3.12, 5.0.8)
  • GitHub Check: baseapp-chats / project-workflow (3.12, 5.0.8)
  • GitHub Check: baseapp-cloudflare-stream-field / project-workflow (3.12, 4.2.15)
  • GitHub Check: baseapp-chats / project-workflow (3.12, 4.2.15)
  • GitHub Check: baseapp-blocks / project-workflow (3.12, 5.0.8)
  • GitHub Check: baseapp-auth-baseapp_auth / project-workflow (3.12, 5.0.8)
  • GitHub Check: baseapp-auth-baseapp_referrals / project-workflow (3.12, 5.0.8)
  • GitHub Check: baseapp-auth-baseapp_auth / project-workflow (3.12, 4.2.15)
  • GitHub Check: baseapp / project-workflow (3.12, 5.0.8)
  • GitHub Check: baseapp-auth-baseapp_referrals / project-workflow (3.12, 4.2.15)
  • GitHub Check: baseapp / project-workflow (3.12, 4.2.15)
🔇 Additional comments (11)
baseapp-reactions/testproject/settings.py (1)

31-31: LGTM! Verify middleware configuration.

The addition of MessageMiddleware is correctly positioned in the middleware stack and aligns with the PR objective to display "Cannot delete profile" messages in Django Admin.

Run this script to verify the middleware configuration across the project:

✅ Verification successful

Middleware configuration verified and correct

The MessageMiddleware is properly configured in all settings files where it's used:

  • Correctly positioned after SessionMiddleware and AuthenticationMiddleware
  • Maintains consistent ordering across test projects
  • Follows Django's middleware requirements for message functionality
🏁 Scripts executed

The following scripts were executed for the analysis:

Script:

#!/bin/bash
# Description: Check for consistent MessageMiddleware configuration across settings files
# and verify it's positioned after SessionMiddleware in all cases

# Search for MessageMiddleware in all settings files
echo "Checking MessageMiddleware configuration:"
rg -A 10 -B 10 "MIDDLEWARE.*=.*\[" | rg -A 10 "MessageMiddleware"

# Verify SessionMiddleware appears before MessageMiddleware
echo -e "\nVerifying middleware order:"
rg -A 15 "SessionMiddleware" | rg -A 10 "MessageMiddleware"

Length of output: 4661


Script:

#!/bin/bash
# Show complete MIDDLEWARE configuration from all settings files
echo "Complete MIDDLEWARE configurations:"
rg -A 20 "MIDDLEWARE.*=.*\[" --multiline

# Extract and compare positions of SessionMiddleware and MessageMiddleware
echo -e "\nChecking middleware order in each file:"
for f in $(rg -l "MIDDLEWARE.*=.*\["); do
  echo "=== $f ==="
  rg -A 20 "MIDDLEWARE.*=.*\[" "$f" | rg "Middleware"
done

Length of output: 19281

baseapp-chats/testproject/settings.py (1)

28-28: LGTM! Consistent middleware configuration.

The addition of MessageMiddleware matches the configuration in baseapp-reactions and is correctly positioned in the middleware stack.

baseapp-organizations/baseapp_organizations/migrations/0002_alter_organization_profile.py (2)

1-6: LGTM! Migration metadata and imports are properly structured.

The migration file follows Django conventions with appropriate imports and metadata.


10-13: LGTM! Dependencies are correctly configured.

The migration properly depends on both the initial migration and the swappable profile model.

baseapp-blocks/testproject/testapp/migrations/0004_alter_user_profile.py (1)

19-26: LGTM! Field configuration aligns with PR objectives.

The OneToOneField configuration with on_delete=PROTECT correctly implements the desired behavior of preventing profile deletion when users are still associated.

A few key points about this implementation:

  • PROTECT ensures data integrity by preventing accidental deletions
  • blank=True, null=True maintains backward compatibility by allowing optional profiles
  • Dynamic related_name using %(class)s prevents naming conflicts
baseapp-reactions/testproject/testapp/migrations/0004_alter_user_profile.py (1)

10-13: LGTM! Dependencies are correctly configured.

The migration properly depends on the previous migration and the swappable profile model.

baseapp-ratings/testproject/testapp/migrations/0005_alter_user_profile.py (1)

1-28: Verify the migration order across all apps.

The changes look good, but since this affects multiple apps, ensure proper migration ordering during deployment.

Run this script to analyze migration dependencies and determine the correct deployment order:

✅ Verification successful

Migration dependencies are properly configured

All apps maintain correct internal migration sequences and properly reference the profile model. No cascade dependencies were found, ensuring data integrity during deployment.

🏁 Scripts executed

The following scripts were executed for the analysis:

Script:

#!/bin/bash
# Description: Analyze migration dependencies to determine deployment order

# Find all relevant migration files
echo "=== Migration Dependencies Analysis ==="
fd --type f ".*alter_user_profile.py$" | while read -r file; do
    dir=$(dirname "$file")
    # Extract app name and dependencies
    app_name=$(echo "$dir" | rg -o "baseapp-[^/]+")
    echo "App: $app_name"
    rg "dependencies = \[" -A 3 "$file"
done

# Check for any existing profile references that might be affected
echo -e "\n=== Existing Profile References ==="
rg "on_delete\s*=\s*.*CASCADE.*profile" --type py

Length of output: 6035

baseapp-follows/testproject/testapp/migrations/0009_alter_user_profile.py (1)

15-27: LGTM! Migration correctly implements PROTECT behavior

The migration properly changes the profile field's on_delete behavior to PROTECT, which aligns with the PR objective of preventing profile deletion when associated users exist. The field configuration follows Django best practices with appropriate use of blank=True, null=True, and dynamic related_name.

baseapp-chats/testproject/testapp/migrations/0010_alter_user_profile.py (1)

15-27: LGTM! Consistent with other app migrations

The migration maintains consistency with other apps by implementing the same PROTECT behavior and field configuration.

baseapp-organizations/testproject/testapp/migrations/0003_alter_user_profile.py (2)

15-27: LGTM! Migration maintains consistency

The migration correctly implements the PROTECT behavior and maintains field configuration consistency with other apps.


10-13: Verify migration dependencies across apps

While the migration correctly implements the PROTECT behavior, since multiple apps are modifying the same User model field, it's important to ensure proper migration ordering to prevent conflicts.

Run this script to check migration dependencies across apps:

Verified

This commit was created on github.com and signed with GitHub’s verified signature. The key has expired.

Verified

This commit was created on github.com and signed with GitHub’s verified signature. The key has expired.
@rafaelhdr rafaelhdr force-pushed the protect-profilable-model branch from a664d8b to c0c71bc Compare January 22, 2025 11:18
Copy link

Quality Gate Failed Quality Gate failed for 'silverlogic_baseapp-backend_baseapp-blocks'

Failed conditions
0.0% Coverage on New Code (required ≥ 80%)

See analysis details on SonarQube Cloud

Copy link

Quality Gate Failed Quality Gate failed for 'silverlogic_baseapp-backend_baseapp-auth'

Failed conditions
0.0% Coverage on New Code (required ≥ 80%)

See analysis details on SonarQube Cloud

Copy link

Quality Gate Failed Quality Gate failed for 'silverlogic_baseapp-backend_baseapp-comments'

Failed conditions
0.0% Coverage on New Code (required ≥ 80%)

See analysis details on SonarQube Cloud

Copy link

Quality Gate Failed Quality Gate failed for 'silverlogic_baseapp-backend_baseapp-chats'

Failed conditions
0.0% Coverage on New Code (required ≥ 80%)

See analysis details on SonarQube Cloud

Copy link

Quality Gate Failed Quality Gate failed for 'silverlogic_baseapp-backend_baseapp-follows'

Failed conditions
0.0% Coverage on New Code (required ≥ 80%)

See analysis details on SonarQube Cloud

Copy link

Quality Gate Failed Quality Gate failed for 'silverlogic_baseapp-backend_baseapp-pages'

Failed conditions
0.0% Coverage on New Code (required ≥ 80%)

See analysis details on SonarQube Cloud

Copy link

Quality Gate Failed Quality Gate failed for 'silverlogic_baseapp-backend_baseapp-profiles'

Failed conditions
0.0% Coverage on New Code (required ≥ 80%)

See analysis details on SonarQube Cloud

Copy link

Quality Gate Failed Quality Gate failed for 'silverlogic_baseapp-backend_baseapp-ratings'

Failed conditions
0.0% Coverage on New Code (required ≥ 80%)

See analysis details on SonarQube Cloud

Copy link

Quality Gate Failed Quality Gate failed for 'silverlogic_baseapp-backend_baseapp-reports'

Failed conditions
0.0% Coverage on New Code (required ≥ 80%)

See analysis details on SonarQube Cloud

Copy link

Quality Gate Failed Quality Gate failed for 'silverlogic_baseapp-backend_baseapp-reactions'

Failed conditions
0.0% Coverage on New Code (required ≥ 80%)

See analysis details on SonarQube Cloud

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.

None yet

4 participants