Skip to content

Conversation

@Luke-Oldenburg
Copy link
Contributor

Summary of the problem

Describe your changes

@Luke-Oldenburg Luke-Oldenburg changed the title [DX] Refactor UserSession to User::Session [Namespacing] Refactor UserSession to User::Session Dec 8, 2025
@Luke-Oldenburg
Copy link
Contributor Author

The solution to this error is to update all rows in activities to have the correct class name but I'm not sure what we can do as a temporary fix to prevent downtime.
Screenshot From 2025-12-08 00-51-39

@Luke-Oldenburg Luke-Oldenburg marked this pull request as ready for review December 8, 2025 17:51
@Luke-Oldenburg Luke-Oldenburg requested a review from a team December 8, 2025 17:51
Comment on lines +1 to +11
class UpdateUserSessionTypes < ActiveRecord::Migration[8.0]
def up
PublicActivity::Activity.where(trackable_type: "UserSession").update_all(trackable_type: "User::Session")
PaperTrail::Version.where(item_type: "UserSession").update_all(item_type: "User::Session")
end

def down
PublicActivity::Activity.where(trackable_type: "User::Session").update_all(trackable_type: "UserSession")
PaperTrail::Version.where(item_type: "User::Session").update_all(item_type: "UserSession")
end
end
Copy link

Choose a reason for hiding this comment

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

Bug: Deployment order issue: NameError when trackable_type = "UserSession" is constantized before migration runs.
Severity: CRITICAL | Confidence: High

🔍 Detailed Analysis

The trackable_is_deletable? method calls constantize on trackable_type. If the new code is deployed before the migration db/migrate/20251208174819_update_user_session_types.rb runs, activity records with trackable_type = "UserSession" will still exist. Since UserSession is removed, calling "UserSession".constantize raises a NameError, causing pages displaying activities (e.g., /my, event audit logs) to crash.

💡 Suggested Fix

Ensure the migration db/migrate/20251208174819_update_user_session_types.rb is run and completed in production before deploying the new code that removes the UserSession class.

🤖 Prompt for AI Agent
Review the code at the location below. A potential bug has been identified by an AI
agent.
Verify if this is a real issue. If it is, propose a fix; if not, explain why it's not
valid.

Location: db/migrate/20251208174819_update_user_session_types.rb#L1-L11

Potential issue: The `trackable_is_deletable?` method calls `constantize` on
`trackable_type`. If the new code is deployed before the migration
`db/migrate/20251208174819_update_user_session_types.rb` runs, activity records with
`trackable_type = "UserSession"` will still exist. Since `UserSession` is removed,
calling `"UserSession".constantize` raises a `NameError`, causing pages displaying
activities (e.g., `/my`, event audit logs) to crash.

Did we get this right? 👍 / 👎 to inform future reviews.
Reference ID: 6234838

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